-
Notifications
You must be signed in to change notification settings - Fork 1
/
roach_parser.py
44 lines (34 loc) · 961 Bytes
/
roach_parser.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
import sys
import csv
import datetime
# Rewritten by Max Shron from code by John Myles White
# ARGV
# ARGV[1] == Window Size
# ARGV[2] == Window End Offset from Today
roachcode = "04M"
window = int(sys.argv[1])
back = int(sys.argv[2])
datestring = "%Y-%m-%d %H:%M:%S"
now = datetime.datetime.now()
#key: zip, value: {restaurant,code}
zipcodes = {}
for data in csv.reader(sys.stdin):
if data[0] == 'CAMIS': continue
d = now - datetime.datetime.strptime(data[8],datestring)
d = d.days
if window+back > d > back:
camis = data[0]
zipcode = data[5]
code = data[10]
zipcodes.setdefault(zipcode,{}).setdefault(camis,[]).append(code)
zipcodes_out = {}
for z in zipcodes:
total = 0
roach = 0
for r in zipcodes[z]:
total += 1
if roachcode in zipcodes[z][r]:
roach += 1
zipcodes_out[z] = [str(total),str(roach)]
for z,v in zipcodes_out.iteritems():
print ','.join([z] + v)