-
-
Save libkoi/993f9bc17bee51b607834f2a39bfd279 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import re | |
import pywikibot | |
from datetime import datetime | |
LIMIT = 50000000 | |
site = pywikibot.Site('commons', 'commons', user='Crystal-bot') | |
site.login() | |
page = pywikibot.Page(pywikibot.Link('LargeImage', default_namespace=10, source=site)) | |
gen = page.getReferences(only_template_inclusion=True, namespaces=6) | |
curtime = datetime.utcnow() | |
curtime_ts = curtime.strftime('%Y-%m-%d %H:%M:%S') | |
count = 0 | |
match = 0 | |
replaced = 0 | |
for fp in (gen): | |
# if not isinstance(fp, pywikibot.page._filepage.FilePage): | |
# continue | |
# if replaced >= 10: | |
# print("Test completed.") | |
# break | |
count += 1 | |
try: | |
if fp.latest_file_info['width'] * fp.latest_file_info['height'] < LIMIT: | |
match += 1 | |
curr = re.sub(r"\{\{([Ll]arge ?[Ii]mage|[Tt]ooLarge|[Ii]nteractiveViewer|[Ll]I)\}\}\n?", "", fp.text) | |
if curr != fp.text: | |
replaced += 1 | |
fp.text = curr | |
print(f"{str(replaced)}/{str(count)}: Replacing in {str(fp.title())}") | |
fp.save("Bot: Remove [[Template:LargeImage]] from files smaller than 50MP", botflag=True) | |
except: | |
pass | |
print("========") | |
print(f"{curtime_ts}: Found {str(match)}, replaced {str(replaced)} in {str(count)} files.") | |
print("========") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment