Created
December 1, 2018 16:09
-
-
Save pyfisch/9e23203635700d322b6a8cd2bb8e1f4c to your computer and use it in GitHub Desktop.
Wikidata FischBot Task 6
This file contains hidden or 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
import logging | |
import pywikibot | |
import csv | |
site = pywikibot.Site('wikidata', 'wikidata') | |
def load_data(): | |
with open('data.csv', newline='') as csvfile: | |
return list(csv.DictReader(csvfile)) | |
def do_edits(): | |
for entry in load_data(): | |
try: | |
item = pywikibot.ItemPage(site, entry['Unique ID']) | |
name = entry['Name_SL'] | |
if '(' in name: | |
logging.warning(f'Wikidata names should not contain parentheses: {name}') | |
edit = dict() | |
edit['labels'] = {'sl': name} | |
if entry['Description_SL']: | |
edit['descriptions'] = {'sl': entry['Description_SL']} | |
item.editEntity(edit, summary='Add labels and descriptions for SL medical terms') | |
except Exception as e: | |
logging.error(f'An exception occured while processing the line {entry}: {e}') | |
do_edits() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment