-
Notifications
You must be signed in to change notification settings - Fork 12
/
common.py
157 lines (148 loc) · 3.84 KB
/
common.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import re
import datetime
def create_new_record():
return dict({
"ncmec_number" : "",
"namus_number" : "",
"org_name" : "",
"org" : "",
"org_contact" : "",
"agency_name" : "",
"agency_contact" : "",
"date" : "",
"city" : "",
"state" : "",
"county" : "",
"country" : "",
"circumstance" : "",
"first_name" : "",
"middle_name" : "",
"last_name" : "",
"age" : "",
"sex" : "",
"race" : "",
"eye_color" : "",
"hair_color" : "",
"weight" : "",
"height" : "",
"photo" : "",
"aged_photo" : ""
})
def clean_date(d):
try:
date = str(datetime.datetime.strptime(d, "%b %d, %Y %I:%M:%S %p"))
except ValueError:
date = str(datetime.datetime.strptime(d, "%B %d, %Y %H:%M"))
return date
def extract_agency_info(contact):
match = re.search("[\d-]*\d{3}[ |]*-\d{3}[ |]*-\d{4}", contact)
agency_phone = ""
if match:
agency_phone = match.group(0)
agency_name = contact.replace(agency_phone, "").strip()
return (agency_name, agency_phone)
def convert_state_abbrev(state_abbrev):
states = {
"AL" : "Alabama",
"AK" : "Alaska",
"AZ" : "Arizonia",
"AR" : "Arkansas",
"CA" : "California",
"CO" : "Colorado",
"CT" : "Connecticut",
"DE" : "Delaware",
"FL" : "Florida",
"GA" : "Georgia",
"HI" : "Hawaii",
"ID" : "Idaho",
"IL" : "Illinois",
"IN" : "Indiana",
"IA" : "Iowa",
"KS" : "Kansas",
"KY" : "Kentucky",
"LA" : "Louisiana",
"ME" : "Maine",
"MT" : "Montana",
"NE" : "Nebraska",
"NV" : "Nevada",
"NH" : "New Hampshire",
"NJ" : "New Jersey",
"NM" : "New Mexico",
"NY" : "New York",
"NC" : "North Carolina",
"ND" : "North Dakota",
"OH" : "Ohio",
"OK" : "Oklahoma",
"OR" : "Oregon",
"MD" : "Maryland",
"MA" : "Massachusetts",
"MI" : "Michigan",
"MN" : "Minnesota",
"MS" : "Mississippi",
"MO" : "Missouri",
"PA" : "Pennsylvania",
"RI" : "Rhode Island",
"SC" : "South Carolina",
"SD" : "South Dakota",
"TN" : 'Tennessee',
"TX" : "Texas",
"UT" : "Utah",
"VT" : "Vermont",
"VA" : "Virginia",
"WA" : "Washington",
"WV" : "West Virginia",
"WI" : "Wisconsin",
"WY" : "Wyoming"
}
return states[state_abbrev]
def capitalize(s):
if s:
arr = s.strip().split(" ")
rets = ""
for subs in arr:
rets += subs[0].upper() + subs[1:].lower() + " "
return rets.strip()
return ""
def clean_race(race):
races = ["White", "Black/African American", "Asian or Pacific Islander", "Native American", "Non-White Hispanic/Latino", "White Hispanic/Latino", "Other", "Unknown"]
if race in races:
return race
elif race.lower() == "white":
return "White"
elif race.lower() == "black":
return "Black/African American"
elif race.lower() == "whitehisp":
return "White Hispanic/Latino"
elif race.lower() == "biracial":
return "Other"
elif race.lower() == "pacific" or race.lower() == "asian":
return "Asian or Pacific Islander"
elif race.lower() == "hispanic":
return "Non-White Hispanic/Latino"
elif race.lower() == "amind":
return "Native American"
elif race.lower() == "white":
return "White"
return "Unknown"
def clean_eye_color(eye_color):
eye_colors = ["Blue", "Brown", "Hazel", "Gray", "Green", "Pink", "Maroon", "Black", "Multicolor"]
if eye_color in eye_colors:
return eye_color
if capitalize(eye_color) in eye_colors:
return capitalize(eye_color)
return "Unknown"
def clean_hair_color(hair_color):
hair_colors = ["Brown", "Sandy", "Black", "Gray", "White", "Blonde", "Red/Auburn"]
if hair_color in hair_colors:
return hair_color
elif capitalize(hair_color) in hair_colors:
return capitalize(hair_color)
elif hair_color.lower() == "gray or partially gray" or hair_color.lower() == "grey":
return "Gray"
elif hair_color.lower() == "red" or hair_color.lower() == "auburn":
return "Red/Auburn"
elif hair_color.lower() == "ltbrown":
return "Brown"
elif hair_color.lower() == "blond/strawberry":
return "Blonde"
return "Unknown"