-
Notifications
You must be signed in to change notification settings - Fork 2
/
load_names.py
74 lines (58 loc) · 1.54 KB
/
load_names.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from models import *
import csv
with open('female_diminutives.csv', 'rU') as f:
reader = csv.reader(f)
for row in reader:
with db.atomic():
f_n = Formal_Name.create_or_get(name = row[0])[0]
for i in row[1:]:
with db.atomic():
Diminutive_Name.create_or_get(
formal_name = f_n
, name = i
, sex = 'F'
)
with open('male_diminutives.csv', 'rU') as f:
reader = csv.reader(f)
for row in reader:
with db.atomic():
f_n = Formal_Name.create_or_get(name = row[0])[0]
for i in row[1:]:
try:
with db.atomic():
Diminutive_Name.create(
formal_name = f_n
, name = i
, sex = 'M'
)
except Exception as e:
if 'duplicate' in e.message:
diminutive = Diminutive_Name.get(
Diminutive_Name.formal_name == f_n
, Diminutive_Name.name == i
)
diminutive.sex = 'N'
with db.atomic():
diminutive.save()
else:
print e
with open('known_dupes.csv', 'rU') as f:
reader = csv.DictReader(f)
for row in reader:
with db.atomic():
person = Person.get_or_create(
first_name = row['primary_first']
, middle_name = row['primary_middle']
, last_name = row['primary_last']
, name_suffix = row['primary_suffix']
, nickname = row['primary_nickname']
)[0]
Person_Name.create(
person=person
, first_name = row['alt_first']
, middle_name = row['alt_middle']
, last_name = row['alt_last']
, name_suffix = row['alt_suffix']
, nickname = row['alt_nickname']
)
print 'Fully loaded.'