-
Notifications
You must be signed in to change notification settings - Fork 0
/
crawl.py
33 lines (29 loc) · 807 Bytes
/
crawl.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
import json
from argparse import ArgumentParser
from pathlib import Path
parser = ArgumentParser(description="crawl LightenUpCalgary")
parser.add_argument(
"year",
type=int,
help="year",
)
args = parser.parse_args()
year = args.year
data = Path("data")
data.mkdir(exist_ok=True)
module_name = f"lighten_up_calgary_{year}"
class_name = f"LightenUpCalgary{year}"
try:
module = __import__(module_name)
my_class = getattr(module, class_name)
records = my_class.get_addresses()
with open(data / f"{year}.json", "w") as f:
json.dump(records, f, indent=2)
except ImportError:
print(f"module not found: {module_name}")
except AttributeError:
print(f"class not found: {class_name}")
except Exception as e:
print(e)
else:
print(f"{len(records)} records found")