-
Notifications
You must be signed in to change notification settings - Fork 2
/
workOnIntegratingISNI.py
50 lines (39 loc) · 1.28 KB
/
workOnIntegratingISNI.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import sqlite3
import json
#constants
VIAFISNImapfile = open('VIAFISNImap.json', 'r')
VIAFISNImap = json.load(VIAFISNImapfile)
#conn = sqlite3.connect('/data/users/kleinm/wikidata/authorities.db')
conn = sqlite3.connect('/data/users/kleinm/wikidata/tests.db')
c = conn.cursor()
isniWrites = list()
def inISNIwrites(idrec):
qnum = idrec[1]
isni = idrec[3]
for willWrite in isniWrites:
#if the the isni number exists
if willWrite[3] == isni:
#and if the it's the same wikidata item
if willWrite[1] == qnum:
#then we've found a duplicate
return True
#otherwise either the isni is unique in the idval sense, or it belongs to two wikidata item
return False
for row in c.execute('''select * from authorities where idtyp like 'VIAF';'''):
qnum = row[1]
viafnum = row[3]
print qnum, viafnum
try:
isnilist = VIAFISNImap[viafnum]
for isni in isnilist:
idrec = ('xx', qnum, 'ISNI', isni)
if not inISNIwrites(idrec):
isniWrites.append(idrec)
else:
pass
except KeyError:
pass
#write isnis to db
print len(isniWrites)
c.executemany('''INSERT INTO authorities VALUES (?,?,?,?)''', isniWrites)
conn.commit()