forked from CU-Community-Coders/evictions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eviction_prep.py
64 lines (53 loc) · 2.03 KB
/
eviction_prep.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
import csv
import re
import sys
from airtable import Airtable
cases = {}
with open(sys.argv[1]) as infile:
reader = csv.DictReader(infile)
event_types = set()
airtable = Airtable("appnHTbPMc3f8dELw", "Evictions")
print(airtable.get_all())
for rec in reader:
dock13 = rec['DOCK13']
event_type = rec['OUTINT']
if rec['CASINTX'] == 'Eviction':
print(rec)
if dock13:
if dock13 not in cases:
cases[dock13] = {}
if rec['PDTYPE'] == 'P':
cases[dock13]['plaintiff'] = rec['N28']
elif rec['PDTYPE'] == 'D':
cases[dock13]['defendant'] = rec['N28']
x = re.search("Schedule Date: (\S+) Event: (.+)$", rec['DATETIP'])
(schedule_date, event) = x.groups()
if(event_type == 'First App'):
cases[dock13]['First App'] = schedule_date
if event_type == 'Eviction':
cases[dock13]['Eviction'] = schedule_date
if event_type == 'Hearing':
cases[dock13]['Hearing'] = schedule_date
event_types.add(event_type)
for case_id in cases.keys():
print(case_id)
case = cases[case_id]
first_app = case['First App'] if 'First App' in case else None
eviction = case['Eviction'] if 'Eviction' in case else None
hearing = case['Hearing'] if 'Hearing' in case else None
plaintiff = case['plaintiff'] if 'plaintiff' in case else None
defendant = case['defendant'] if 'defendant' in case else None
out_rec = {
'CaseID': case_id,
'Plaintiff': plaintiff,
'Defendant': defendant,
'FirstApp': first_app,
'Hearing': hearing,
'Eviction': eviction
}
case_record = airtable.match('CaseID', case_id)
if case_record:
sparse_record = {k: v for k, v in out_rec.items() if v is not None}
airtable.update(case_record['id'], sparse_record)
else:
airtable.insert(out_rec)