Skip to content

Commit c7b5bf8

Browse files
committed
http > https and some minor formatting
1 parent b35ac6e commit c7b5bf8

File tree

2 files changed

+34
-23
lines changed

2 files changed

+34
-23
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ The wrapper will, well, wrap those.
2626

2727
You will get your result as a dictionary, which represents the
2828
JSON output you would get [from the Overpass API
29-
directly](http://overpass-api.de/output_formats.html#json>). So you
29+
directly](https://overpass-api.de/output_formats.html#json>). So you
3030
could do this for example:
3131

3232
```python
@@ -47,11 +47,11 @@ The API object takes a few parameters:
4747

4848
#### endpoint
4949

50-
The default endpoint is `http://overpass-api.de/api/interpreter` but
50+
The default endpoint is `https://overpass-api.de/api/interpreter` but
5151
you can pass in another instance:
5252

5353
```python
54-
api = overpass.API(endpoint=http://overpass.myserver/interpreter)
54+
api = overpass.API(endpoint=https://overpass.myserver/interpreter)
5555
```
5656

5757
#### timeout
@@ -76,7 +76,7 @@ them like to normal query to the API.
7676
#### MapQuery
7777

7878
This is a shorthand for a [complete ways and
79-
relations](http://wiki.openstreetmap.org/wiki/Overpass_API/Language_Guide#Recursing_up_and_down:_Completed_ways_and_relations)
79+
relations](https://wiki.openstreetmap.org/wiki/Overpass_API/Language_Guide#Recursing_up_and_down:_Completed_ways_and_relations)
8080
query in a bounding box (the 'map call'). You just pass the bounding box
8181
to the constructor:
8282

overpass/api.py

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
from .errors import (OverpassSyntaxError, TimeoutError, MultipleRequestsError,
77
ServerLoadError, UnknownOverpassError, ServerRuntimeError)
88

9+
910
class API(object):
10-
"""A simple Python wrapper for the OpenStreetMap Overpass API"""
11+
"""A simple Python wrapper for the OpenStreetMap Overpass API."""
1112

1213
SUPPORTED_FORMATS = ["geojson", "json", "xml"]
1314

1415
# defaults for the API class
1516
_timeout = 25 # second
16-
_endpoint = "http://overpass-api.de/api/interpreter"
17+
_endpoint = "https://overpass-api.de/api/interpreter"
1718
_debug = False
1819

1920
_QUERY_TEMPLATE = "[out:{out}];{query}out {verbosity};"
@@ -26,45 +27,52 @@ def __init__(self, *args, **kwargs):
2627
self._status = None
2728

2829
if self.debug:
29-
# http://stackoverflow.com/a/16630836
30+
# https://stackoverflow.com/a/16630836
3031
try:
3132
import http.client as http_client
3233
except ImportError:
3334
# Python 2
3435
import httplib as http_client
3536
http_client.HTTPConnection.debuglevel = 1
3637

37-
# You must initialize logging, otherwise you'll not see debug output.
38+
# You must initialize logging,
39+
# otherwise you'll not see debug output.
3840
logging.basicConfig()
3941
logging.getLogger().setLevel(logging.DEBUG)
4042
requests_log = logging.getLogger("requests.packages.urllib3")
4143
requests_log.setLevel(logging.DEBUG)
4244
requests_log.propagate = True
4345

44-
45-
def Get(self, query, responseformat="geojson", verbosity="body", build=True):
46-
"""Pass in an Overpass query in Overpass QL"""
47-
46+
def Get(self,
47+
query,
48+
responseformat="geojson",
49+
verbosity="body",
50+
build=True):
51+
"""Pass in an Overpass query in Overpass QL."""
4852
# Construct full Overpass query
4953
if build:
50-
full_query = self._ConstructQLQuery(query, responseformat=responseformat, verbosity=verbosity)
54+
full_query = self._ConstructQLQuery(query,
55+
responseformat=responseformat,
56+
verbosity=verbosity)
5157
else:
5258
full_query = query
5359

5460
if self.debug:
5561
logging.getLogger().info(query)
56-
62+
5763
# Get the response from Overpass
5864
raw_response = self._GetFromOverpass(full_query)
5965

6066
if responseformat == "xml" or responseformat.startswith("csv"):
6167
return raw_response
62-
68+
6369
response = json.loads(raw_response)
6470

65-
# Check for valid answer from Overpass. A valid answer contains an 'elements' key at the root level.
71+
# Check for valid answer from Overpass.
72+
# A valid answer contains an 'elements' key at the root level.
6673
if "elements" not in response:
67-
raise UnknownOverpassError("Received an invalid answer from Overpass.")
74+
raise UnknownOverpassError(
75+
"Received an invalid answer from Overpass.")
6876

6977
# If there is a 'remark' key, it spells trouble.
7078
overpass_remark = response.get('remark', None)
@@ -88,10 +96,15 @@ def _ConstructQLQuery(self, userquery, responseformat, verbosity):
8896

8997
if responseformat == "geojson":
9098
template = self._GEOJSON_QUERY_TEMPLATE
91-
complete_query = template.format(query=raw_query, verbosity=verbosity)
99+
complete_query = template.format(
100+
query=raw_query,
101+
verbosity=verbosity)
92102
else:
93103
template = self._QUERY_TEMPLATE
94-
complete_query = template.format(query=raw_query, out=responseformat, verbosity=verbosity)
104+
complete_query = template.format(
105+
query=raw_query,
106+
out=responseformat,
107+
verbosity=verbosity)
95108

96109
if self.debug:
97110
print(complete_query)
@@ -110,7 +123,7 @@ def _GetFromOverpass(self, query):
110123
timeout=self.timeout,
111124
headers={'Accept-Charset': 'utf-8;q=0.7,*;q=0.7'}
112125
)
113-
126+
114127
except requests.exceptions.Timeout:
115128
raise TimeoutError(self._timeout)
116129

@@ -125,9 +138,7 @@ def _GetFromOverpass(self, query):
125138
raise ServerLoadError(self._timeout)
126139
raise UnknownOverpassError(
127140
"The request returned status code {code}".format(
128-
code=self._status
129-
)
130-
)
141+
code=self._status))
131142
else:
132143
r.encoding = 'utf-8'
133144
return r.text

0 commit comments

Comments
 (0)