diff options
Diffstat (limited to 'proposals.py')
-rwxr-xr-x | proposals.py | 92 |
1 files changed, 50 insertions, 42 deletions
diff --git a/proposals.py b/proposals.py index ae6a451..92f1c28 100755 --- a/proposals.py +++ b/proposals.py @@ -2,6 +2,7 @@ import html import json import sys +from collections.abc import Container import pywikiapi import mwparserfromhell @@ -9,20 +10,41 @@ import requests OSMWIKI_ENDPOINT = 'https://wiki.openstreetmap.org/w/api.php' -osmwiki = pywikiapi.Site(OSMWIKI_ENDPOINT) - # https://wiki.openstreetmap.org/w/index.php?title=Template:Proposal_page&action=edit -res = requests.get( - OSMWIKI_ENDPOINT, - params=dict( - action='expandtemplates', - prop='wikitext', - format='json', - text='{{#invoke:languages/table|json}}', - ), -) -langs = json.loads(res.json()['expandtemplates']['wikitext']) + +def run(): + res = requests.get( + OSMWIKI_ENDPOINT, + params=dict( + action='expandtemplates', + prop='wikitext', + format='json', + text='{{#invoke:languages/table|json}}', + ), + ) + langs: dict[str, dict] = json.loads(res.json()['expandtemplates']['wikitext']) + + osmwiki = pywikiapi.Site(OSMWIKI_ENDPOINT) + + proposals = [] + for page in osmwiki.query_pages( + generator='embeddedin', + geititle='Template:Proposal page', + geilimit='max', + prop='revisions', + rvprop='content', + rvslots='main', + ): + proposal = parse_proposal(page, langs) + if proposal: + proposals.append(proposal) + + proposals.sort(key=sort_key, reverse=True) + + json.dump( + [{k: v for k, v in p.items() if v is not None} for p in proposals], sys.stdout + ) def get_template_val(tpl, name): @@ -34,9 +56,6 @@ def get_template_val(tpl, name): return value -proposals = [] - - def eprint(*args): print(*args, file=sys.stderr) @@ -67,14 +86,7 @@ def is_stub(doc): return False -for page in osmwiki.query_pages( - generator='embeddedin', - geititle='Template:Proposal page', - geilimit='max', - prop='revisions', - rvprop='content', - rvslots='main', -): +def parse_proposal(page: dict, langs: Container[str]) -> dict | None: page_title = page['title'] text = page['revisions'][0]['slots']['main']['content'] doc = mwparserfromhell.parse(text) @@ -85,7 +97,7 @@ for page in osmwiki.query_pages( if not proposal_page_templates: eprint('{{Proposal Page}} not found in', page_title) - continue + return None for comment in doc.ifilter_comments(): # remove comments like <!-- Date the RFC email is sent to the Tagging list: YYYY-MM-DD --> @@ -102,7 +114,7 @@ for page in osmwiki.query_pages( eprint(f'WARNING {status} proposal is a stub', page['title']) else: eprint('skipping stub', page['title']) - continue + return None name = get_template_val(tpl, 'name') if name: @@ -130,20 +142,19 @@ for page in osmwiki.query_pages( if parts[0] in langs: lang = parts[0] - proposals.append( - dict( - page_title=page_title, - lang=lang, - name=name, - status=status, - definition=definition, - draft_start=draft_start, - rfc_start=rfc_start, - vote_start=vote_start, - authors=users, - ) + return dict( + page_title=page_title, + lang=lang, + name=name, + status=status, + definition=definition, + draft_start=draft_start, + rfc_start=rfc_start, + vote_start=vote_start, + authors=users, ) + STATUSES = { 'voting': 0, 'post-vote': 1, @@ -171,8 +182,5 @@ def sort_key(proposal): return (-STATUSES.get(proposal['status'], 10), date) -proposals.sort(key=sort_key, reverse=True) - -json.dump( - [{k: v for k, v in p.items() if v is not None} for p in proposals], sys.stdout -) +if __name__ == "__main__": + run() |