Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattiasostmar/00d99a935923b32ed6b6bca1b5029165 to your computer and use it in GitHub Desktop.
Save mattiasostmar/00d99a935923b32ed6b6bca1b5029165 to your computer and use it in GitHub Desktop.
import pywikibot
from pywikibot import pagegenerators as pg
site = pywikibot.Site(fam="commons")
cat = pywikibot.Category(site, 'Category:Media_from_the_National_Museums_of_World_Culture')
gen = pg.CategorizedPageGenerator(cat)
for page in gen:
filePage = pywikibot.FilePage(page)
try:
# Do something... E.g. add template for speedy deletion
filePage.text = "{{speedydelete|broken file upload}}\n" + current
filePage.save("Add template for speedy deletion due to no image uploaded, only text")
except pywikibot.exceptions.PageRelatedError as e: # normally means there's no such page
print("{} seems to not exist on Commons".format(filePage)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment