-
Notifications
You must be signed in to change notification settings - Fork 0
/
atob.py
executable file
·95 lines (85 loc) · 3.52 KB
/
atob.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env python3
'''
++++
++=o===o+:
=o=========+
:o===========+
:============+
===========++
++oo==oo+:
++++ mm
+ ## ##
:=+=oooo++:+ m#####m ####### m####m ##m###m
=============o++ " mmm## ## ##" "## ##" "##
+===============o: m##"""## ## ## ## ## ##
+=================o+ ##mmm### ##mmm "##mm##" ###mm##"
o==================: """" "" """" """" "" """
++:==+++=++oo=============+ ++:==+++==:++
++=o======o+ +:============ :+=o===========o+=:
:o===========o= +======o: =o===================o=
:o===============o+:+ +:==+: :o=======================o+
=o===================o=oooo== =============================
:=============================: +=+++=+ :============================o:
o=============================+=o======+ o=============================o
==============================oo=======o+ +o==============================
o=============================o+======== +o=============================o
+=============================+ +=+++=+ +==============================
++============================+ +============================++
++=========================++ ++=========================++
:======================o: :o=====================o:
:+o===============o+: :+o===============o+:
++=+oo=====oo+=++ +:++oo=====oo+=:+
'''
def parse_args():
import argparse
parser = argparse.ArgumentParser(
usage=__doc__,
description="Run a series of Overpass API queries and convert the results to GEOJSON",
formatter_class=argparse.RawTextHelpFormatter,
)
parser.add_argument(
"--bounds",
"-b",
default=[],
help="The bounding region from which to retrieve data.\n"
"\t(default: London Borough of Ealing boundaries)",
action='append'
)
parser.add_argument(
"--timeout",
"-t",
type=int,
default=60,
help="Timeout for Overpass API queries, in seconds.\n\t(default: 60)",
)
parser.add_argument(
"--verbose",
"-v",
action="count",
default=0,
help="By default, shows nothing.\n"
"\t-v prints actions \n"
"\t-vv gives protocol debug output",
)
parser.add_argument("infile", type=argparse.FileType("r"))
return parser.parse_args()
def get_data(queryfile, bounds, timeout, verbosity):
import overpass
api = overpass.API(timeout=timeout)
newline = "\n"
query = f"""
(
{newline.join(f' area[name="{bound}"];' for bound in set(bounds))}
)->.searchArea;
(
{newline.join(f" {spec.strip()}(area.searchArea);" for spec in queryfile)}
);
(._;>;);
"""
return api.get(query, responseformat="xml", verbosity="meta")
if __name__ == "__main__":
import sys
args = parse_args()
if not args.bounds:
args.bounds = ["London Borough of Ealing"]
print(get_data(args.infile, args.bounds, args.timeout, args.verbose))