-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfind-liar.py
executable file
·76 lines (53 loc) · 1.65 KB
/
find-liar.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
#!/usr/bin/env python3
import sys
import json
import datetime
from pathlib import Path
if len(sys.argv) == 1:
raise Exception("Missing argument, job number")
JOB = sys.argv[1]
def read_json(path):
with open(path, 'r') as f:
return json.loads(f.read())
def parse_date(date_str):
return datetime.datetime.strptime(date_str, "%Y-%m-%d")
def question_answer(answer):
if answer == 'yes':
return True
if answer == 'no':
return False
return None
# parsed dob information
pw1_path = str(Path.home().joinpath('.nyc-data', 'dob', str(JOB), 'pw1.json'))
dob_info_path = str(Path.home().joinpath('.nyc-data', 'dob', str(JOB), '{}.json'.format(JOB)))
pw1 = read_json(pw1_path)
dob_info = read_json(dob_info_path)
rent_stab_answer = question_answer(pw1['rent_control'].lower())
prefilingdate = dob_info[0]['prefilingdate']
job_year = prefilingdate[0:4]
BBL = dob_info[0]['bbl']
bbl_info_path = str(Path.home().joinpath('.nyc-data', 'bbl', BBL, '{}.json'.format(BBL)))
bbl_info = read_json(bbl_info_path)
dof_year = str(int(job_year) + 1)
if dof_year not in bbl_info['dof']['unitCounts']:
stabilized_in_year = None
else:
stabilized_in_year = (bbl_info['dof']['unitCounts'][dof_year] > 0)
if (not rent_stab_answer) and bbl_info['dof']['rentStabilized']:
if stabilized_in_year:
is_liar = 'yes'
liar_boolean = True
else:
is_liar = 'suspicious'
liar_boolean = None
else:
is_liar = 'no'
liar_boolean = False
result = {
"job": JOB,
"date": prefilingdate,
"rentStabAnswer": rent_stab_answer,
"liarStatus": is_liar,
"liar": liar_boolean
}
print(json.dumps(result))