-
Notifications
You must be signed in to change notification settings - Fork 0
/
namesearch.py
52 lines (44 loc) · 1.3 KB
/
namesearch.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
'''
A command-line program for searching a clean State Dept Consular names JSON file.
Asks for a last name, then first name.
'''
import json
def main():
last = raw_input('LAST name (or part of last name): ')
first = raw_input('FIRST name (or part of first name):')
results = []
try:
fp = open('output_clean.json')
except IOError:
print 'There was an error opening the JSON data file. Please make sure that the file [output_clean.json] has been properly generated!'
data = fp.read()
fp.close()
all_names = json.loads(data)
del data
print 'Searching ' + str(all_names['count']) + ' listed entries...'
people = all_names['people']
for person in people:
if last in person['last_name']:
if first in person['first_name']:
results.append(person)
if len(results) > 0:
print 'Found ' + str(len(results)) + ' matches:'
for result in results:
print '=========='
prettyDisplay(result)
print '=========='
else:
print '================='
print 'Found No results.'
print '================='
def prettyDisplay(person):
print 'NAME: ' + person['first_name'] + ' ' + person['last_name']
print 'POSITIONS: '
count = 0
for position in person['positions']:
count += 1
print str(count)
for key in position:
print '-------> ' + key + ': ' + position[key]
if __name__ == '__main__':
main()