Skip to content

Commit

Permalink
Merge pull request #152 from KaartGroup/variable_lines
Browse files Browse the repository at this point in the history
Handle variable numbers of lines in Overpass status page
  • Loading branch information
mvexel authored Jul 24, 2022
2 parents 7804c87 + ddf9a50 commit dc96611
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
10 changes: 7 additions & 3 deletions overpass/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,13 @@ def _api_status() -> dict:

available_re = re.compile(r'\d(?= slots? available)')
available_slots = int(
available_re.search(lines[3]).group()
if available_re.search(lines[3])
else 0
next(
(
available_re.search(line).group()
for line in lines
if available_re.search(line)
), 0
)
)

waiting_re = re.compile(r'(?<=Slot available after: )[\d\-TZ:]{20}')
Expand Down
6 changes: 6 additions & 0 deletions tests/overpass_status/no_slots_waiting_six_lines.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Connected as: 0123456789
Current time: 2022-06-15T22:13:27Z
Announced endpoint: lz4.overpass-api.de/api/
Rate limit: 2
2 slots available now.
Currently running queries (pid, space limit, time limit, start time):
6 changes: 6 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ def test_geojson_live():
@pytest.mark.parametrize(
"response,slots_available,slots_running,slots_waiting",
[
(
"tests/overpass_status/no_slots_waiting_six_lines.txt",
2,
(),
()
),
(
"tests/overpass_status/no_slots_waiting.txt",
2,
Expand Down

0 comments on commit dc96611

Please sign in to comment.