From bb8c09f9f169d96d29c6c3c3c81012c15499a190 Mon Sep 17 00:00:00 2001 From: Michael Murtaugh Date: Thu, 8 Feb 2018 10:53:43 +0100 Subject: [PATCH] mediawiki recentfiles --- makefile | 4 +- scripts/leaflet.py | 2 +- scripts/mediawiki.py | 189 ++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 190 insertions(+), 5 deletions(-) diff --git a/makefile b/makefile index 7e448b3..f52e430 100644 --- a/makefile +++ b/makefile @@ -17,7 +17,7 @@ archive.json: https://pzwiki.wdka.nl/mediadesign/Category:2004 > archive.json drop.node.json: drop.json - cat drop.json | python scripts/leaflet.py gallery --recursive --direction 2 > drop.node.json + cat drop.json | python scripts/leaflet.py gallery --reverse --recursive --direction 2 > drop.node.json about.json: about.txt python scripts/texthierarchy.py < about.txt > about.json @@ -25,3 +25,5 @@ about.json: about.txt index.json: archive.json about.json drop.node.json python scripts/includenodes.py xpub.top.json > index.json +recent.json: web.touch + python scripts/mediawiki.py recentfiles --usercategory Xpub ... \ No newline at end of file diff --git a/scripts/leaflet.py b/scripts/leaflet.py index f079559..d842163 100755 --- a/scripts/leaflet.py +++ b/scripts/leaflet.py @@ -20,7 +20,7 @@ def tiles_path_for (n): def autolink (text): def sub (m): return u'LINK'.format(m.group(0)) - return re.sub(r"https?://[\S]+", sub, text, re.I) + return re.sub(r'(?{1}
Uploaded by {3}'.format( + page_url(wiki, usagepage), + usagepage.page_title, + page_url(wiki, userpage), + r['user']) + else: + item['text'] = '{1}
Uploaded by {3}'.format( + page_url(wiki, filepage), + filepage.page_title, + page_url(wiki, userpage), + r['user']) + + # print (json.dumps(item)) + items_to_output.append(item) + # honor --limit + count += 1 + if args.limit and count == args.limit: + break + + except APIError as e: + print ("Error {0}, skipping".format(e)) + + if args.limit and count == args.limit: + break + # continue the query if possible (pre-loop)... + if 'continue' in qq: + qargs['aicontinue'] = qq['continue']['aicontinue'] + else: + # we've reached the end of the query data + break + + # OUTPUT RESULTS + # reverse to be chronological + items_to_output.reverse() + if args.json: + with open(args.json, "a") as f: + for x in items_to_output: + print (json.dumps(x), file=f) + else: + for x in items_to_output: + print (json.dumps(x)) if __name__ == "__main__": @@ -312,6 +488,13 @@ if __name__ == "__main__": ap_article.add_argument("--html", default=False, action="store_true") ap_article.set_defaults(func=make_category) + ap_recentfiles = subparsers.add_parser('recentfiles', help='Incrementally update a json file with information about recent files') + ap_recentfiles.add_argument("--usercategory", help="limit to activity by users that are members of this category") + ap_recentfiles.add_argument("--limit", type=int, help="limit") + ap_recentfiles.add_argument("--oldest", default=None, help="No results earlier than this timestamp (e.g. 2018-01-01T00:00:00Z)") + ap_recentfiles.add_argument("--json", default=None, help="Use this json file as both input (to check last timestampt) and output -- append results chronologically as json-stream.") + ap_recentfiles.set_defaults(func=recentfiles) + args = ap.parse_args()