Browse Source

added function to automate entity creation on wikidata

master
corsaronero 1 year ago
parent
commit
ef764f4bfd
4 changed files with 47 additions and 3 deletions
  1. +4
    -2
      main.py
  2. BIN
      wikidata/.wdPEP.py.kate-swp
  3. BIN
      wikidata/__pycache__/wdPEP.cpython-310.pyc
  4. +43
    -1
      wikidata/wdPEP.py

+ 4
- 2
main.py View File

@ -24,6 +24,8 @@ listOfCountries = ['nicaragua']
wikidataPEP = WikidataPEP(config) wikidataPEP = WikidataPEP(config)
wikidataPEP.importMembersOfParliamentDict(listOfCountries)
#wikidataPEP.importMembersOfParliamentDict(listOfCountries)
wikidataPEP.checkForEntityIds(listOfCountries)
#wikidataPEP.checkForEntityIds(listOfCountries)
wikidataPEP.createMemberOnWikidata()

BIN
wikidata/.wdPEP.py.kate-swp View File


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


+ 43
- 1
wikidata/wdPEP.py View File

@ -66,5 +66,47 @@ class WikidataPEP(object):
print(name) print(name)
print('is a human') print('is a human')
def createMemberOnWikidata(self):
from wikibaseintegrator import wbi_login, WikibaseIntegrator
from wikibaseintegrator.datatypes import ExternalID, Item
from wikibaseintegrator.wbi_config import config as wbi_config
wbi_config['USER_AGENT'] = 'PEPimport/1.0 (https://www.wikidata.org/wiki/User:Username)'
# login object
login_instance = wbi_login.OAuth2(consumer_token='', consumer_secret='')
wbi = WikibaseIntegrator(login=login_instance)
# data type object, e.g. for a NCBI gene entrez ID
isHuman = Item(value='Q5', prop_nr='P31')
occupationPolitician = ExternalID(value='Q82955', prop_nr='P106')
occupationDeputy = ExternalID(value='Q1055894', prop_nr='P106')
#referenceURL = URL(value='http://legislacion.asamblea.gob.ni/Tablas%20Generales.nsf/InfoDiputado.xsp?documentId=3D4CFDC4B3006D70062587C5007C29E1&action=openDocument&SessionID=1868803A06AB73D50B7F89BD0AB', prop_nr='P106')
# print(isHuman)
# print(referenceURL)
# data goes into a list, because many data objects can be provided to
data1 = [isHuman]
data2 = [occupationDeputy]
data3 = [occupationPolitician]
# Create a new item
item = wbi.item.new()
# Set an english label
item.labels.set(language='en', value='Carlos Humberto Ruíz')
# Set a French description
item.descriptions.set(language='en', value='Nicaraguan National Assembly Deputy')
item.claims.add(data1)
#item.claims.add(data2)
#item.claims.add(data3)
print(item.write())

Loading…
Cancel
Save