-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathversion3.py
More file actions
54 lines (28 loc) · 1.12 KB
/
version3.py
File metadata and controls
54 lines (28 loc) · 1.12 KB
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
# vim: set expandtab ts=4 sw=4 filetype=python fileencoding=utf8:
"""
Catch when we fail to parse a value into a floating point number.
Otherwise, only print successful matches.
"""
import csv
def handle_house_row(row):
try:
sale_price = float(row["price"])
except ValueError as ex:
print("Sorry, could not parse this data {0!r} into a float!".format(row["price"]))
# print("Sorry, could not parse this data {price!r} into a float!".format(**row))
return
else:
current_status = row["sourceStatus"]
allowed_statuses = ["Active", "Back On Market", "Price Reduced"]
if sale_price < 200 * 1000 and current_status in allowed_statuses:
print(
"House at {street} has status {sourceStatus} and price "
"{price}: good match.".format( **row))
def do_everything():
home_path_file_name = "home-path.csv"
home_path_file = open(home_path_file_name, "r")
csv_thingy = csv.DictReader(home_path_file)
for house_row in csv_thingy:
handle_house_row(house_row)
if __name__ == "__main__":
do_everything()