Browse Source

now adding references to a property works too, in function editMemberOnWikidata()

master
corsaronero 1 year ago
parent
commit
f395b87ab6
3 changed files with 35 additions and 18 deletions
  1. +1
    -1
      main.py
  2. BIN
      wikidata/__pycache__/wdPEP.cpython-310.pyc
  3. +34
    -17
      wikidata/wdPEP.py

+ 1
- 1
main.py View File

@ -30,4 +30,4 @@ wikidataPEP = WikidataPEP(config)
#wikidataPEP.createMemberOnWikidata() #wikidataPEP.createMemberOnWikidata()
#wikidataPEP.editMemberOnWikidata()
wikidataPEP.editMemberOnWikidata('Q116918332')

BIN
wikidata/__pycache__/wdPEP.cpython-310.pyc View File


+ 34
- 17
wikidata/wdPEP.py View File

@ -102,6 +102,8 @@ class WikidataPEP(object):
# Set an english label # Set an english label
item.labels.set(language='en', value='Carlos Humberto Ruíz') item.labels.set(language='en', value='Carlos Humberto Ruíz')
# Carlos Humberto Ruiz has the Qid Q116918332
# Set a French description # Set a French description
item.descriptions.set(language='en', value='Nicaraguan National Assembly Deputy') item.descriptions.set(language='en', value='Nicaraguan National Assembly Deputy')
@ -112,15 +114,16 @@ class WikidataPEP(object):
def editMemberOnWikidata(self):
def editMemberOnWikidata(self, Qid):
from wikibaseintegrator import wbi_login, WikibaseIntegrator from wikibaseintegrator import wbi_login, WikibaseIntegrator
from wikibaseintegrator.datatypes import ExternalID, Item
from wikibaseintegrator.datatypes import ExternalID, Item, Time, String
from wikibaseintegrator.wbi_config import config as wbi_config from wikibaseintegrator.wbi_config import config as wbi_config
from wikibaseintegrator.wbi_enums import ActionIfExists from wikibaseintegrator.wbi_enums import ActionIfExists
from wikibaseintegrator.wbi_enums import WikibaseDatePrecision
wbi_config['USER_AGENT'] = 'PEPimport/1.0 (https://www.wikidata.org/wiki/User:Username)'
wbi_config['USER_AGENT'] = 'PEPimport/1.0 (https://www.wikidata.org/wiki/User:Alpcentaur)'
# login object # login object
login_instance = wbi_login.OAuth2(consumer_token='', consumer_secret='') login_instance = wbi_login.OAuth2(consumer_token='', consumer_secret='')
@ -128,29 +131,43 @@ class WikidataPEP(object):
wbi = WikibaseIntegrator(login=login_instance) wbi = WikibaseIntegrator(login=login_instance)
# data type object, e.g. for a NCBI gene entrez ID # data type object, e.g. for a NCBI gene entrez ID
isHuman = Item(value='Q5', prop_nr='P31')
occupationPolitician = Item(value='Q82955', prop_nr='P106')
occupationDeputy = Item(value='Q1055894', prop_nr='P106')
referenceURL = ExternalID(value='http://legislacion.asamblea.gob.ni/Tablas%20Generales.nsf/InfoDiputado.xsp?documentId=3D4CFDC4B3006D70062587C5007C29E1&action=openDocument&SessionID=1868803A06AB73D50B7F89BD0AB', prop_nr='P854')
# isHuman = Item(value='Q5', prop_nr='P31')
# occupationPolitician = Item(value='Q82955', prop_nr='P106')
# occupationDeputy = Item(value='Q1055894', prop_nr='P106')
# referenceURL = ExternalID(value='http://legislacion.asamblea.gob.ni/Tablas%20Generales.nsf/InfoDiputado.xsp?documentId=3D4CFDC4B3006D70062587C5007C29E1&action=openDocument&SessionID=1868803A06AB73D50B7F89BD0AB', prop_nr='P854')
# print(isHuman) # print(isHuman)
# print(referenceURL) # print(referenceURL)
# data goes into a list, because many data objects can be provided to
data1 = [isHuman]
references = [
[
ExternalID(value='http://legislacion.asamblea.gob.ni/Tablas%20Generales.nsf/InfoDiputado.xsp?documentId=3D4CFDC4B3006D70062587C5007C29E1&action=openDocument&SessionID=1868803A06AB73D50B7F89BD0AB', prop_nr='P854'),
Time(time='+2023-02-27T00:00:00Z', prop_nr='P813', precision=WikibaseDatePrecision.DAY)
]
]
occupationDeputy = Item(value='Q1055894', prop_nr='P106', references=references)
## data goes into a list, because many data objects can be provided to
# data1 = [isHuman]
data2 = [occupationDeputy] data2 = [occupationDeputy]
data3 = [occupationPolitician]
data4 = [referenceURL]
# get item for Qid
item = wbi.item.get(entity_id='Q116918332')
# data3 = [occupationPolitician]
# data4 = [referenceURL]
## get item for Qid
item = wbi.item.get(entity_id=Qid)
# print(item.claims)
# Set an english label # Set an english label
item.labels.set(language='en', value='Carlos Humberto Ruíz', action_if_exists=ActionIfExists.KEEP)
#item.labels.set(language='en', value='Carlos Humberto Ruíz', action_if_exists=ActionIfExists.KEEP)
# Set a French description # Set a French description
item.descriptions.set(language='en', value='Nicaraguan National Assembly Deputy', action_if_exists=ActionIfExists.KEEP)
#item.descriptions.set(language='en', value='Nicaraguan National Assembly Deputy', action_if_exists=ActionIfExists.KEEP)
item.claims.add(data4)
#item.claims.add(data2)
#item.claims.add(data4)
item.claims.add(data2)
#item.claims.add(data3) #item.claims.add(data3)
print(item.write()) print(item.write())

Loading…
Cancel
Save