diff options
| author | 2026-05-17 13:29:02 +0000 | |
|---|---|---|
| committer | 2026-05-17 13:29:02 +0000 | |
| commit | 2e4e8740ebb09926846834f78c833321d635db77 (patch) | |
| tree | b98c80eb086e8c487bd4cb5ab6a880ed93308187 | |
| parent | wikibot: Move some scripts to wikibot-manual (diff) | |
| signature | ||
wikibot-manual(archivebot): Update in bulk
It only writes to wiki pages it only should be changing, so avoid doing
updates slowly and spamming #archiveteam-bs
| -rw-r--r-- | wikibot-manual/archivebot.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/wikibot-manual/archivebot.py b/wikibot-manual/archivebot.py index 7246a8d..ae8d656 100644 --- a/wikibot-manual/archivebot.py +++ b/wikibot-manual/archivebot.py @@ -30,6 +30,35 @@ import pywikibot.pagegenerators as pagegenerators from archiveteamfun import * + +#{{ stubbed out changes call, only valid if the page is only edited by the bot. +import atexit +BATCH_SIZE = 50 +pending_changes = {} +_original_save = pywikibot.Page.save +site = pywikibot.Site() + +def commit_pending_changes(): + global pending_changes + if not pending_changes: return + print('[Wiki] Submitting %s changes.' % (len(pending_changes))) + for title, data in pending_changes.items(): + page = pywikibot.Page(site, title) + page.text = data['text'] + _original_save(page, data['summary']) + print("[Wiki] Page [[%(title)s{title}]] updated with summary: %(summary)s" % {'title': title, 'summary': data['summary']}) + pending_changes.clear() + +def stub_save(self, summary = ""): + global pending_changes + pending_changes[self.title()] = {'text': self.text, 'summary': summary} + print("[Wiki Stub] Saved [[%(page)s]] locally with summary: %(summary)s" % {'page': self.title(), 'summary': summary}) + if len(pending_changes) >= BATCH_SIZE: commit_pending_changes() + +atexit.register(commit_pending_changes) +pywikibot.Page.save = stub_save +#}} + Entry = collections.namedtuple('Entry', ('sorturl', 'url', 'label', 'note', 'line')) truncationpattern = re.compile(r'^[^:/]+://(www\.)?') |
