Skip to content

Commit

Permalink
Merge branch 'main' into pr/140
Browse files Browse the repository at this point in the history
  • Loading branch information
mvexel committed Feb 13, 2024
2 parents 9cc83a6 + 72a45ad commit 4367f4f
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 30 deletions.
5 changes: 5 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# These are supported funding model platforms

github: [mvexel]
patreon: mvexel
liberapay: mvexel
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
max-parallel: 5
matrix:
python-version: [3.7, 3.8, 3.9]
python-version: ["3.8", "3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v1
Expand Down
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
language: python
python:
- 3.7
- 3.8
- 3.9
- 3.10
- 3.11
install:
- sudo apt-get install libgeos-dev
- pip install -r requirements-dev.txt
Expand Down
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
Overpass API python wrapper
===========================

**Looking for a maintainer**
*Hi there, I am the original author of this project. I no longer have time to maintain it but it looks like it's still useful. I'd like to talk to someone who thinks they can take this on. Drop me a line at [email protected]. Thanks! Martijn van Exel*

Python bindings for the OpenStreetMap [Overpass
API](http://wiki.openstreetmap.org/wiki/Overpass_API).

Expand Down
29 changes: 12 additions & 17 deletions overpass/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,7 @@ def __init__(self, *args, **kwargs):
self._status = None

if self.debug:
# https://stackoverflow.com/a/16630836
try:
import http.client as http_client
except ImportError:
# Python 2
import httplib as http_client
import http.client as http_client
http_client.HTTPConnection.debuglevel = 1

# You must initialize logging,
Expand Down Expand Up @@ -151,19 +146,18 @@ def _api_status() -> dict:
available_slots = int(
next(
(
available_re.search(line).group()
m.group()
for line in lines
if available_re.search(line)
if (m := available_re.search(line))
), 0
)
)

waiting_re = re.compile(r'(?<=Slot available after: )[\d\-TZ:]{20}')
waiting_slots = tuple(
datetime.strptime(
waiting_re.search(line).group(), "%Y-%m-%dT%H:%M:%S%z"
)
for line in lines if waiting_re.search(line)
datetime.strptime(m.group(), "%Y-%m-%dT%H:%M:%S%z")
for line in lines
if (m := waiting_re.search(line))
)

current_idx = next(
Expand Down Expand Up @@ -247,7 +241,7 @@ def _construct_ql_query(self, userquery, responseformat, verbosity, date):
raw_query += ";"

if date:
date = f'[date:"{date.strftime("%Y-%m-%dT%H:%M:%SZ")}"]'
date = f'[date:"{date:%Y-%m-%dT%H:%M:%SZ}"]'

if responseformat == "geojson":
template = self._GEOJSON_QUERY_TEMPLATE
Expand Down Expand Up @@ -280,16 +274,17 @@ def _get_from_overpass(self, query):

self._status = r.status_code

if self._status != 200:
if self._status == 200:
if self._status == 400:
raise OverpassSyntaxError(query)
elif self._status == 429:
raise MultipleRequestsError()
elif self._status == 504:
raise ServerLoadError(self._timeout)
raise UnknownOverpassError(
"The request returned status code {code}".format(code=self._status)
)
else:
raise UnknownOverpassError(
f"The request returned status code {self._status}"
)
else:
r.encoding = "utf-8"
return r
5 changes: 3 additions & 2 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pytest>=6.2.0
pytest>=7.4.0
requests-mock[fixture]
tox>=4.6.3
tox>=3.20.1
geojson>=1.3.1
geojson>=1.3.1
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
osm2geojson>=0.1.30
requests>=2.8.1
requests>=2.31.0
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
keywords=["openstreetmap", "overpass", "wrapper"],
classifiers=[
"License :: OSI Approved :: Apache Software License",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Topic :: Scientific/Engineering :: GIS",
"Topic :: Utilities",
],
Expand Down
2 changes: 1 addition & 1 deletion tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def test_api_status(response: Path, slots_available: int, slots_running: Tuple[d
map_query = overpass.MapQuery(37.86517, -122.31851, 37.86687, -122.31635)
api.get(map_query)

assert api.slots_available <= 2 and api.slots_available >= 0
assert 0 <= api.slots_available <= 2
assert api.slots_available == slots_available

assert isinstance(api.slots_running, tuple)
Expand Down
7 changes: 4 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py{37,38,39}
envlist = py{38,39,310,311}
skip_missing_interpreters = true

[testenv]
Expand All @@ -8,6 +8,7 @@ commands = python -m pytest

[gh-actions]
python =
3.7: py37
3.8: py38
3.9: py39
3.9: py39
3.10: py310
3.11: py311

0 comments on commit 4367f4f

Please sign in to comment.