@@ -41,33 +41,20 @@ def __init__(self,
4141 requests_log .propagate = True
4242
4343 def Get (self , query ):
44- """Pass in an Overpass query in Overpass XML or Overpass QL"""
44+ """Pass in an Overpass query in Overpass QL"""
4545
46- payload = {"data" : self ._ConstructQLQuery (query )}
47-
48- try :
49- r = requests .get (self .endpoint , params = payload , timeout = self .timeout )
50- except requests .exceptions .Timeout :
51- return self ._ConstructError (
52- 'Query timed out. API instance is set to time out in {timeout} seconds. '
53- 'Try passing in a higher value when instantiating this API:'
54- 'api = Overpass.API(timeout=60)' .format (timeout = self .timeout ))
55-
56- self ._status = r .status_code
57-
58- if self ._status != 200 :
59- if self ._status == 400 :
60- return self ._ConstructError ('Query syntax error' )
61- elif self ._status == 500 :
62- return self ._ConstructError ('Overpass internal server error' )
63-
64- response = json .loads (r .text )
46+ response = json .loads (
47+ self ._GetFromOverpass (
48+ self ._ConstructQLQuery (query )))
6549
6650 if "elements" not in response or len (response ["elements" ]) == 0 :
6751 return self ._ConstructError ('No OSM features satisfied your query' )
6852
6953 return response
7054
55+ def Search (self , feature_type , regex = False ):
56+ """Search for something."""
57+
7158 def _ConstructError (self , msg ):
7259 return {
7360 "status" : self ._status ,
@@ -80,3 +67,29 @@ def _ConstructQLQuery(self, userquery):
8067 if not userquery .endswith (";" ):
8168 userquery += ";"
8269 return "[out:json];" + userquery + "out body;"
70+
71+ def _GetFromOverpass (self , query ):
72+ """This sends the API request to the Overpass instance and
73+ returns the raw result, or an error."""
74+
75+ payload = {"data" : query }
76+
77+ try :
78+ r = requests .get (self .endpoint , params = payload , timeout = self .timeout )
79+ except requests .exceptions .Timeout :
80+ return self ._ConstructError (
81+ 'Query timed out. API instance is set to time out in {timeout} seconds. '
82+ 'Try passing in a higher value when instantiating this API:'
83+ 'api = Overpass.API(timeout=60)' .format (timeout = self .timeout ))
84+
85+ self ._status = r .status_code
86+
87+ if self ._status != 200 :
88+ if self ._status == 400 :
89+ return self ._ConstructError ('Query syntax error' )
90+ elif self ._status == 500 :
91+ return self ._ConstructError ('Overpass internal server error' )
92+ else :
93+ return self ._ConstructError ('Something unexpected happened' )
94+
95+ return r .text
0 commit comments