Skip to content

Instantly share code, notes, and snippets.

@pyfisch
Created December 1, 2018 16:09
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 pyfisch/9e23203635700d322b6a8cd2bb8e1f4c to your computer and use it in GitHub Desktop.
Save pyfisch/9e23203635700d322b6a8cd2bb8e1f4c to your computer and use it in GitHub Desktop.
Wikidata FischBot Task 6
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