User:Popcorndude/botcode2
Jump to navigation
Jump to search
import pywikibot import re wd = pywikibot.Site('wikidata', 'wikidata').data_repository() pattern = re.compile("^IC \d{3,4}$") def dostuff(qid): item = pywikibot.ItemPage(wd, qid) item.get() try: for cl in item.claims['P528']: t = cl.getTarget() if type(t) == str and pattern.match(t): if 'en' not in item.labels.keys() or item.labels['en'] == '': item.editLabels({'en':t}) if 'en' not in item.descriptions.keys() or item.descriptions['en'] == '': item.editDescriptions({'en':item.claims['P31'][0].get()['labels']['en'] + " in the constellation " + item.claims['P59'][0].get()['labels']['en']}) return True return False except: return False import starlist #list of items that have P528, P31, and P59 claims for q in starlist.stars: dostuff(q)