summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xfind_archived_proposals_without_template.py26
-rwxr-xr-xproposals.py92
2 files changed, 66 insertions, 52 deletions
diff --git a/find_archived_proposals_without_template.py b/find_archived_proposals_without_template.py
index 0acb4bf..50dbbd9 100755
--- a/find_archived_proposals_without_template.py
+++ b/find_archived_proposals_without_template.py
@@ -10,14 +10,20 @@ import mwparserfromhell
OSMWIKI_ENDPOINT = 'https://wiki.openstreetmap.org/w/api.php'
-osmwiki = pywikiapi.Site(OSMWIKI_ENDPOINT)
-for page in osmwiki.query_pages(
- generator='categorymembers',
- gcmtitle='Category:Archived proposals',
- gcmlimit='max',
- prop='templates',
- tltemplates='Template:Proposal page'
-):
- if not 'templates' in page:
- print(page['title'])
+def run():
+ osmwiki = pywikiapi.Site(OSMWIKI_ENDPOINT)
+
+ for page in osmwiki.query_pages(
+ generator='categorymembers',
+ gcmtitle='Category:Archived proposals',
+ gcmlimit='max',
+ prop='templates',
+ tltemplates='Template:Proposal page',
+ ):
+ if not 'templates' in page:
+ print(page['title'])
+
+
+if __name__ == "__main__":
+ run()
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()