-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpull_sales.py
More file actions
50 lines (40 loc) · 1.7 KB
/
Copy pathpull_sales.py
File metadata and controls
50 lines (40 loc) · 1.7 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
"""Pull Elko County vacant-land sale records via the assessor advanced search export.
Two forms:
uv run python pull_sales.py --months 36
uv run python pull_sales.py 2023-08-01 2026-08-01 V data/raw/sales_window_20260802.json
The rolling form is what refresh.py calls: it computes the window backwards from today
and writes a date-stamped file into data/raw/, which publish_snapshot.py then redacts and
compresses into the committed set the notebook reads. A rerun always lands on current data
without anyone editing a date.
"""
import sys
from datetime import date
from dateutil.relativedelta import relativedelta
import elko_client
def query(dos_min, dos_max, acreage_min="40", vi_cd="V"):
q = {
"type": "s",
"query[parcel][acreage_min]": acreage_min,
"query[sale][dos_min]": dos_min,
"query[sale][dos_max]": dos_max,
"sort": "last_sale_date",
}
if vi_cd:
q["query[sale][vi_cd]"] = vi_cd
return q
def rolling(months, out_dir="data/raw"):
end = date.today()
start = end - relativedelta(months=months)
out = f"{out_dir}/sales_window_{end:%Y%m%d}.json"
return start.isoformat(), end.isoformat(), out
if __name__ == "__main__":
if sys.argv[1:2] == ["--months"]:
dos_min, dos_max, out = rolling(int(sys.argv[2]))
vi = "V"
else:
dos_min, dos_max, vi, out = sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4]
vi = "" if vi == "any" else vi
print(f"pulling {dos_min}..{dos_max} vi={vi or 'ANY'}", file=sys.stderr)
rows = elko_client.pull("/search/adv", query(dos_min, dos_max, vi_cd=vi),
"/export/adv/s", out)
print(f"wrote {out}: {len(rows)} records", file=sys.stderr)