From 867d5b230606fad23fb2f0d4a7c1a665773cbf3a Mon Sep 17 00:00:00 2001 From: Evan Derickson Date: Wed, 15 Jun 2022 15:39:14 -0700 Subject: [PATCH 1/2] Search for the slots available instead Don't assume it's always in same position, check instead --- overpass/api.py | 10 +++++++--- tests/overpass_status/no_slots_waiting_six_lines.txt | 6 ++++++ tests/test_api.py | 6 ++++++ 3 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 tests/overpass_status/no_slots_waiting_six_lines.txt diff --git a/overpass/api.py b/overpass/api.py index f3f8651a9ac..0536c75dca8 100644 --- a/overpass/api.py +++ b/overpass/api.py @@ -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}') diff --git a/tests/overpass_status/no_slots_waiting_six_lines.txt b/tests/overpass_status/no_slots_waiting_six_lines.txt new file mode 100644 index 00000000000..20d2659b0ac --- /dev/null +++ b/tests/overpass_status/no_slots_waiting_six_lines.txt @@ -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): diff --git a/tests/test_api.py b/tests/test_api.py index dc3657b32e2..beb11d581fe 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -89,6 +89,12 @@ def test_geojson_live(): @pytest.mark.parametrize( "response,slots_available,slots_running,slots_waiting", [ + ( + "tests/overpass_status/no_slots_waiting_extra_lines.txt", + 2, + (), + () + ), ( "tests/overpass_status/no_slots_waiting.txt", 2, From ddf9a50a66e83adee78ad56be9911b7463ab55db Mon Sep 17 00:00:00 2001 From: Evan Derickson Date: Wed, 15 Jun 2022 15:44:07 -0700 Subject: [PATCH 2/2] Fix renamed file --- tests/test_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_api.py b/tests/test_api.py index beb11d581fe..d3603a16067 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -90,7 +90,7 @@ def test_geojson_live(): "response,slots_available,slots_running,slots_waiting", [ ( - "tests/overpass_status/no_slots_waiting_extra_lines.txt", + "tests/overpass_status/no_slots_waiting_six_lines.txt", 2, (), ()