In [3]:
import pywikibot
import csv
import re
import requests
import urllib.parse
import time
import datetime
import unicodedata

from pywikibot import pagegenerators as pg

#with open('ArtistsInCollections.rq', 'r') as query_file:
#with open('ASRcollectie.rq', 'r') as query_file:
with open('PictoRightDACSnoADAGGP.rq', 'r') as query_file:
    QUERY = query_file.read()

wikidata_site = pywikibot.Site("wikidata", "wikidata")
generator = pg.WikidataSPARQLPageGenerator(QUERY, site=wikidata_site)
languages = ['nl','en','es','fr','de', 'it']
for item in generator:
    
    site = pywikibot.Site("wikidata", "wikidata")
    repo = site.data_repository()
    # item = pywikibot.ItemPage(repo, "Q362796")
    namelist = set()
    aliases = item.get()["aliases"]
    labels = item.get()["labels"]
    for lang in labels:
        if lang in languages:
            namelist.add(labels[lang])
    
    for lang in aliases:
        if lang in languages:
            for index, alias in enumerate(aliases[lang]):
                namelist.add(aliases[lang][index])
    
        
    print (namelist)
    item_dict = item.get() #Get the item dictionary
    clm_dict = item_dict["claims"] # Get the claim dictionary
    #geboorte_list = clm_dict["P569"] #geboortedata
    #geboortejaar = NULL
    #for geboortedatum in geboorte_list:
     #   datumobject = geboortedatum.getTarget()
#        print (datumobject.time)
    for name in namelist:
        url = "https://www.adagp.fr/fr/mysearch/rp_rights?keyword=" + urllib.parse.quote_plus(name)
        print (url)
        time.sleep(1)
        r = requests.get(url,  verify=False)
        r.text
        # Naam: <a href="/fr/identities/lin-utzon-190678" title="Lin Utzon">
        #          Lin Utzon<span class="date"> (1946)  </span></a>
        #Thomas Kröswang -> Thomas Kroswang
        print (name)

#        a = re.search('<a href="/fr/identities/[^"]+-([0-9]+)" title="' + re.escape(name) + '">', r.text) 
        a = re.search('<a href="/fr/identities/[^"]+-([0-9]+)" title="' + re.escape(name) + '">([^>]+>( \([0-9- ]+\)))?', r.text, re.IGNORECASE) 
        
#        b = re.search('<span class="date"> *\(([0-9- ]+)\) *<\/a>', r.text) 
        print ("RUN")
        code =""
#        name=""
#        date=""
#        repro=""
#        if b:
#            date = (b.group(1))
        if a:
            code = (a.group(1))
            print (code)
            print (a)
            if a.group(3) is not None:
                name = name + a.group(3) 
            print (name)
            claim = pywikibot.Claim(repo, u'P3901')
            claim.setTarget(code)
            statedin = pywikibot.Claim(repo, u'P248')
            itis = pywikibot.ItemPage(repo, "Q71530142")
            statedin.setTarget(itis)
            
            namedas = pywikibot.Claim(repo, u'P1810')
            namedas.setTarget(name)
            
            adagpcode = pywikibot.Claim(repo, u'P854')
            adagpcode.setTarget(url)

            refdate = pywikibot.Claim(repo, u'P813')
            today = datetime.datetime.today()
            date = pywikibot.WbTime(year=today.year, month=today.month, day=today.day)
            refdate.setTarget(date)
#            claim.addSources([statedin, refdate], summary=u'Adding sources.')
            claim.addSources([statedin, namedas, refdate, adagpcode], summary=u'Adding sources.')
            item.addClaim(claim, summary=u'Add ADAGP code')

            
#            name = (a.group(2))    

#            website = x.group(1)
#            if website.find("wikipedia") == -1:
#                if website.find(" ") == -1:
#                    stringclaim = pywikibot.Claim(repo, u'P856')
#                    stringclaim.setTarget(website)
#                    item.addClaim(stringclaim, summary=u'Adding URL from RKD')
                
 
 
{'Grazia Varisco'}
https://www.adagp.fr/fr/mysearch/rp_rights?keyword=Grazia+Varisco
WARNING: /srv/paws/lib/python3.6/site-packages/urllib3/connectionpool.py:851: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)

Grazia Varisco
RUN
{'Aristide Goffinon'}
https://www.adagp.fr/fr/mysearch/rp_rights?keyword=Aristide+Goffinon
WARNING: /srv/paws/lib/python3.6/site-packages/urllib3/connectionpool.py:851: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)

Aristide Goffinon
RUN
{'Laureline Mattiussi'}
https://www.adagp.fr/fr/mysearch/rp_rights?keyword=Laureline+Mattiussi
WARNING: /srv/paws/lib/python3.6/site-packages/urllib3/connectionpool.py:851: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)

Laureline Mattiussi
RUN
{'Margarita Stāraste', 'Margarita Stāraste-Bordevīka'}
https://www.adagp.fr/fr/mysearch/rp_rights?keyword=Margarita+St%C4%81raste
WARNING: /srv/paws/lib/python3.6/site-packages/urllib3/connectionpool.py:851: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)

Margarita Stāraste
RUN
https://www.adagp.fr/fr/mysearch/rp_rights?keyword=Margarita+St%C4%81raste-Bordev%C4%ABka
WARNING: /srv/paws/lib/python3.6/site-packages/urllib3/connectionpool.py:851: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)

Margarita Stāraste-Bordevīka
RUN
{'Yvette Troispoux'}
https://www.adagp.fr/fr/mysearch/rp_rights?keyword=Yvette+Troispoux
WARNING: /srv/paws/lib/python3.6/site-packages/urllib3/connectionpool.py:851: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)

Yvette Troispoux
RUN
{'Fritz Koenig', 'Fritz Konig', 'Koenig, Fritz', 'Fritz König'}
https://www.adagp.fr/fr/mysearch/rp_rights?keyword=Fritz+Koenig
WARNING: /srv/paws/lib/python3.6/site-packages/urllib3/connectionpool.py:851: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)

Fritz Koenig
RUN
https://www.adagp.fr/fr/mysearch/rp_rights?keyword=Fritz+Konig
WARNING: /srv/paws/lib/python3.6/site-packages/urllib3/connectionpool.py:851: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)

Fritz Konig
RUN
https://www.adagp.fr/fr/mysearch/rp_rights?keyword=Koenig%2C+Fritz
WARNING: /srv/paws/lib/python3.6/site-packages/urllib3/connectionpool.py:851: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)

Koenig, Fritz
RUN
https://www.adagp.fr/fr/mysearch/rp_rights?keyword=Fritz+K%C3%B6nig
WARNING: /srv/paws/lib/python3.6/site-packages/urllib3/connectionpool.py:851: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)

Fritz König
RUN
{'Roa', 'ROA'}
https://www.adagp.fr/fr/mysearch/rp_rights?keyword=Roa
WARNING: /srv/paws/lib/python3.6/site-packages/urllib3/connectionpool.py:851: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)

Roa
RUN
https://www.adagp.fr/fr/mysearch/rp_rights?keyword=ROA
WARNING: /srv/paws/lib/python3.6/site-packages/urllib3/connectionpool.py:851: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)

ROA
RUN
{'John Hyatt'}
https://www.adagp.fr/fr/mysearch/rp_rights?keyword=John+Hyatt
WARNING: /srv/paws/lib/python3.6/site-packages/urllib3/connectionpool.py:851: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)

John Hyatt
RUN
{'Marie Rose Lortet'}
https://www.adagp.fr/fr/mysearch/rp_rights?keyword=Marie+Rose+Lortet
WARNING: /srv/paws/lib/python3.6/site-packages/urllib3/connectionpool.py:851: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)

Marie Rose Lortet
RUN
{'Fernand Piet'}
https://www.adagp.fr/fr/mysearch/rp_rights?keyword=Fernand+Piet
WARNING: /srv/paws/lib/python3.6/site-packages/urllib3/connectionpool.py:851: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)

Fernand Piet
RUN
{'Christian Dell'}
https://www.adagp.fr/fr/mysearch/rp_rights?keyword=Christian+Dell
WARNING: /srv/paws/lib/python3.6/site-packages/urllib3/connectionpool.py:851: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)

Christian Dell
RUN
{'Fernand Schirren', 'Ferdinand Schirren'}
https://www.adagp.fr/fr/mysearch/rp_rights?keyword=Fernand+Schirren
WARNING: /srv/paws/lib/python3.6/site-packages/urllib3/connectionpool.py:851: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)

Fernand Schirren
RUN
https://www.adagp.fr/fr/mysearch/rp_rights?keyword=Ferdinand+Schirren
WARNING: /srv/paws/lib/python3.6/site-packages/urllib3/connectionpool.py:851: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)

Ferdinand Schirren
RUN
{'Damian Loeb'}
https://www.adagp.fr/fr/mysearch/rp_rights?keyword=Damian+Loeb
WARNING: /srv/paws/lib/python3.6/site-packages/urllib3/connectionpool.py:851: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)

Damian Loeb
RUN
{'Sigutė Chlebinskaitė'}
https://www.adagp.fr/fr/mysearch/rp_rights?keyword=Sigut%C4%97+Chlebinskait%C4%97
WARNING: /srv/paws/lib/python3.6/site-packages/urllib3/connectionpool.py:851: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)

Sigutė Chlebinskaitė
RUN
{'Eva Mazzucco', 'Eva Maria Mazzucco'}
https://www.adagp.fr/fr/mysearch/rp_rights?keyword=Eva+Mazzucco
WARNING: /srv/paws/lib/python3.6/site-packages/urllib3/connectionpool.py:851: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)

Eva Mazzucco
RUN
https://www.adagp.fr/fr/mysearch/rp_rights?keyword=Eva+Maria+Mazzucco
WARNING: /srv/paws/lib/python3.6/site-packages/urllib3/connectionpool.py:851: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)

Eva Maria Mazzucco
RUN
{'Frank Algernon Stewart', 'Frank Algenon Stewart'}
https://www.adagp.fr/fr/mysearch/rp_rights?keyword=Frank+Algernon+Stewart
WARNING: /srv/paws/lib/python3.6/site-packages/urllib3/connectionpool.py:851: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)

Frank Algernon Stewart
RUN
https://www.adagp.fr/fr/mysearch/rp_rights?keyword=Frank+Algenon+Stewart
WARNING: /srv/paws/lib/python3.6/site-packages/urllib3/connectionpool.py:851: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)

Frank Algenon Stewart
RUN
{'Huba Balvanyos', 'Huba Bálványos'}
https://www.adagp.fr/fr/mysearch/rp_rights?keyword=Huba+Balvanyos
WARNING: /srv/paws/lib/python3.6/site-packages/urllib3/connectionpool.py:851: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)

Huba Balvanyos
RUN
https://www.adagp.fr/fr/mysearch/rp_rights?keyword=Huba+B%C3%A1lv%C3%A1nyos
WARNING: /srv/paws/lib/python3.6/site-packages/urllib3/connectionpool.py:851: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)

Huba Bálványos
RUN
{'Joseph Gabriel Rousseau', 'Gabriel Argy-Rousseau'}
https://www.adagp.fr/fr/mysearch/rp_rights?keyword=Joseph+Gabriel+Rousseau
WARNING: /srv/paws/lib/python3.6/site-packages/urllib3/connectionpool.py:851: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)

Joseph Gabriel Rousseau
RUN
https://www.adagp.fr/fr/mysearch/rp_rights?keyword=Gabriel+Argy-Rousseau
WARNING: /srv/paws/lib/python3.6/site-packages/urllib3/connectionpool.py:851: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)

Gabriel Argy-Rousseau
RUN
{'Richard Sickert', 'walter sickert', 'W. R. Sickert', 'Walter Richard Sickert', 'W.R. Sickert', 'W. Sickert', 'Sickert', 'Walter Sickert'}
https://www.adagp.fr/fr/mysearch/rp_rights?keyword=Richard+Sickert
WARNING: /srv/paws/lib/python3.6/site-packages/urllib3/connectionpool.py:851: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)

Richard Sickert
RUN
https://www.adagp.fr/fr/mysearch/rp_rights?keyword=walter+sickert
WARNING: /srv/paws/lib/python3.6/site-packages/urllib3/connectionpool.py:851: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)

walter sickert
RUN
https://www.adagp.fr/fr/mysearch/rp_rights?keyword=W.+R.+Sickert
WARNING: /srv/paws/lib/python3.6/site-packages/urllib3/connectionpool.py:851: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)

W. R. Sickert
RUN
https://www.adagp.fr/fr/mysearch/rp_rights?keyword=Walter+Richard+Sickert
WARNING: /srv/paws/lib/python3.6/site-packages/urllib3/connectionpool.py:851: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)

Walter Richard Sickert
RUN
https://www.adagp.fr/fr/mysearch/rp_rights?keyword=W.R.+Sickert
WARNING: /srv/paws/lib/python3.6/site-packages/urllib3/connectionpool.py:851: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)

W.R. Sickert
RUN
https://www.adagp.fr/fr/mysearch/rp_rights?keyword=W.+Sickert
WARNING: /srv/paws/lib/python3.6/site-packages/urllib3/connectionpool.py:851: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)

W. Sickert
RUN
https://www.adagp.fr/fr/mysearch/rp_rights?keyword=Sickert
WARNING: /srv/paws/lib/python3.6/site-packages/urllib3/connectionpool.py:851: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)

Sickert
RUN
https://www.adagp.fr/fr/mysearch/rp_rights?keyword=Walter+Sickert
WARNING: /srv/paws/lib/python3.6/site-packages/urllib3/connectionpool.py:851: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)

Walter Sickert
RUN
{'Evariste-Gustave De Buck', 'Evariste Gustave de Buck', 'Evariste Gustave De Buck', 'Evarist de Buck', 'Evariste de Buck', 'Evariste De Buck', 'Evarist De Buck'}
https://www.adagp.fr/fr/mysearch/rp_rights?keyword=Evariste-Gustave+De+Buck
WARNING: /srv/paws/lib/python3.6/site-packages/urllib3/connectionpool.py:851: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)

Evariste-Gustave De Buck
RUN
https://www.adagp.fr/fr/mysearch/rp_rights?keyword=Evariste+Gustave+de+Buck
WARNING: /srv/paws/lib/python3.6/site-packages/urllib3/connectionpool.py:851: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)

Evariste Gustave de Buck
RUN
https://www.adagp.fr/fr/mysearch/rp_rights?keyword=Evariste+Gustave+De+Buck
---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
<ipython-input-3-8cc90246756a> in <module>
     47         url = "https://www.adagp.fr/fr/mysearch/rp_rights?keyword=" + urllib.parse.quote_plus(name)
     48         print (url)
---> 49         time.sleep(1)
     50         r = requests.get(url,  verify=False)
     51         r.text

KeyboardInterrupt: 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]: