finished function for dict import, started function to check for existing entities, already running for ishuman (q5)

This commit is contained in:
corsaronero 2023-02-26 15:24:41 +00:00
parent d01b379ad8
commit 7ade95deb5
6 changed files with 70 additions and 2 deletions

Binary file not shown.

View file

@ -25,3 +25,5 @@ listOfCountries = ['nicaragua']
wikidataPEP = WikidataPEP(config)
wikidataPEP.importMembersOfParliamentDict(listOfCountries)
wikidataPEP.checkForEntityIds(listOfCountries)

33
q5.txt Normal file
View file

@ -0,0 +1,33 @@
started to parse data of members of nicaragua ..
Q107326760
---------
Ángela Espinoza Tórrez
is a human
Q475730
---------
Carlos Humberto Ruíz
is a human
Q107316535
---------
Iris Marina Montenegro Blandón
is a human
Q107332750
---------
Iris Marina Montenegro Blandón
is a human
Q107320919
---------
Iris Marina Montenegro Blandón
is a human
Q63794924
---------
Loria Raquel Dixon Brautigam
is a human
Q107406987
---------
María Haydee Osuna Ruíz
is a human
Q106514750
---------
Shaira Natasha Downs Morgan
is a human

BIN
wikidata/.wdPEP.py.kate-swp Normal file

Binary file not shown.

View file

@ -24,14 +24,47 @@ class WikidataPEP(object):
for country in listOfCountries:
print('started to parse data of member of ' + country + ' ..')
print('started to parse data of members of ' + country + ' ..')
f = open('crawlers/output/' + country +'MemberList.txt')
text = f.read()
self.fullDictionaryMemberLists[country] = eval(text)
print(self.fullDictionaryMemberLists)
#print(self.fullDictionaryMemberLists)
def checkForEntityIds(self, listOfCountries):
from wikibaseintegrator import WikibaseIntegrator
from wikibaseintegrator import wbi_helpers
fullDictionaryMemberLists = self.fullDictionaryMemberLists
for country in listOfCountries:
for memberId in fullDictionaryMemberLists[country].keys():
name = fullDictionaryMemberLists[country][memberId]['name']
results = wbi_helpers.search_entities(search_string=name)
for entityId in results:
wbi = WikibaseIntegrator()
wikidata_item = wbi.item.get(entity_id=entityId)
for claimkey in wikidata_item.get_json()['claims'].keys():
if claimkey == 'P31':
if wikidata_item.get_json()['claims'][claimkey][0]['mainsnak']['datavalue']['value']['id'] == 'Q5':
print(entityId)
print('---------')
print(name)
print('is a human')