-
Notifications
You must be signed in to change notification settings - Fork 18
/
arcgis.py
62 lines (51 loc) · 1.96 KB
/
arcgis.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
from datetime import datetime
try:
from processor import Processor
except:
from .processor import Processor
class ProcessorARCGIS(Processor):
def __init__(self):
super().__init__(type="arcgis")
def get_datasets(self, owner, start_url, fname):
datasets = []
url = start_url
while True:
d = processor.get_json(url)
if d != "NULL":
datasets += d["data"]
if "next" in d["meta"] and d["meta"]["next"]:
url = d["meta"]["next"]
print(f"Next {url}")
else:
break
print(f"Found {len(datasets)} datasets")
prepped = []
for e in datasets:
prepped.append(
[
e["attributes"].get("name", ""),
e["attributes"].get("source", ""),
e.get("links", {}).get("itemPage", ""),
"", # Link to data
"", # FileName
datetime.utcfromtimestamp(
e["attributes"].get("created", 0) / 1000
).strftime("%Y-%m-%d"),
datetime.utcfromtimestamp(
e["attributes"].get("modified", 0) / 1000
).strftime("%Y-%m-%d"),
# ^^ Should really do something better than defaulting to start of epoch
e["attributes"].get("size", ""),
"bytes",
e["attributes"].get("type", ""),
e["attributes"].get("recordCount", ""),
";".join(e["attributes"].get("tags", [])),
"", # Manual tags
self.get_license(e), # license
e["attributes"].get("searchDescription", ""),
]
)
processor.write_csv(fname, prepped)
processor = ProcessorARCGIS()
if __name__ == "__main__":
processor.process()