Skip to content

Instantly share code, notes, and snippets.

@Abbe98
Created November 14, 2019 17:52
Show Gist options
  • Save Abbe98/1fb4f855de08a857f797117a5452c856 to your computer and use it in GitHub Desktop.
Save Abbe98/1fb4f855de08a857f797117a5452c856 to your computer and use it in GitHub Desktop.
import csv
import datetime
import requests
import pywikibot
site = pywikibot.Site('wikidata', 'wikidata')
repo = site.data_repository()
endpoint='https://api.smk.dk/api/v1/iiif/manifest/?id='
def today_as_WbTime():
"""
Get todays date as a WbTime object.
@return: Todays date correctly formated
@rtype: pywikibot.WbTime
"""
today = datetime.date.today()
date = pywikibot.WbTime(year=today.year,
month=today.month,
day=today.day)
return date
def create_statement(item, iiif, source):
claim = pywikibot.Claim(repo, 'P6108')
claim.setTarget(iiif)
item.addClaim(claim, summary='Adding iiif manifest link')
ref_url = pywikibot.Claim(repo, 'P854')
ref_url.setTarget(source)
retrieved = pywikibot.Claim(repo, u'P813')
retrieved.setTarget(today_as_WbTime())
claim.addSources([ref_url, retrieved], summary='Adding source to iiif mainfest link')
with open('query.csv') as csvfile:
spamreader = csv.reader(csvfile)
for row in spamreader:
url = endpoint + row[1]
print(url)
r = requests.get(url)
if r.status == 200:
item = pywikibot.ItemPage(repo, row[0][31:])
item.get()
if 'P6108' not in item.claims:
create_statement(item, iiif, url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment