Page MenuHomePhabricator
Paste P2148

index_refresh.py
ActivePublic

Authored by jayvdb on Oct 3 2015, 8:38 AM.
Referenced Files
F2655644: index_refresh.py
Oct 3 2015, 8:38 AM
Subscribers
None
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import datetime
import pywikibot
from pywikibot.pagegenerators import RecentChangesPageGenerator
from pywikibot.tools import filter_unique
def main():
pywikibot.handle_args()
site = pywikibot.Site()
assert site.family.name == 'wikisource'
page_namespace = site.proofread_page_ns
index_namespace = site.proofread_index_ns
now = datetime.datetime.utcnow()
five_hours_ago = now - datetime.timedelta(hours=5)
print('** find %s namespace %d edits in last five hours'
% (site, page_namespace))
rcgen = RecentChangesPageGenerator(site=site,
namespaces=[page_namespace],
end=five_hours_ago,
total=500,
_filter_unique=filter_unique)
pages = sorted(rcgen)
indexes = set()
for page in pages:
no_ns_title = page._link.title
try:
no_pageno_title, page_no = no_ns_title.rsplit('/', 1)
except:
continue
indexes.add(no_pageno_title)
print('** refreshing %s namespace %d pages'
% (site, index_namespace))
for title in indexes:
index_page = pywikibot.Page(site, title, index_namespace)
if not index_page.exists():
print('somehow %s doesnt exist' % index_page)
else:
index_page.purge()
print('%s purged' % index_page)
if __name__ == "__main__":
main()

Event Timeline

jayvdb changed the title of this paste from untitled to index_refresh.py.
jayvdb updated the paste's language from autodetect to python.