Skip to content
This repository was archived by the owner on Jun 10, 2025. It is now read-only.

Commit ce74e19

Browse files
authored
Merge pull request #150 from KaartGroup/next_slot_available
Convenience properties for when API is next available
2 parents dc96611 + 720b29c commit ce74e19

File tree

6 files changed

+3144
-16
lines changed

6 files changed

+3144
-16
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
.DS_Store
2+
.idea/
23
.pytest_cache/
4+
.vscode/
35
**/__pycache__/
46
*.py[cod]
57
dist/
@@ -11,4 +13,4 @@ eggs/
1113
pip-log.txt
1214
docs/_build/
1315
Pipfile.lock
14-
venv/
16+
venv/

overpass/api.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
import json
88
import logging
99
import re
10-
from datetime import datetime
10+
from datetime import datetime, timezone
1111
from io import StringIO
12+
from math import ceil
13+
from typing import Optional
1214

1315
import geojson
1416
import requests
@@ -204,6 +206,34 @@ def slots_running(self) -> tuple:
204206
"""
205207
return self._api_status()["running_slots"]
206208

209+
@property
210+
def slot_available_datetime(self) -> Optional[datetime]:
211+
"""
212+
:returns: None if a slot is available now (no wait needed) or a datetime representing when the next slot will become available
213+
"""
214+
if self.slots_available:
215+
return None
216+
return min(self.slots_running + self.slots_waiting)
217+
218+
@property
219+
def slot_available_countdown(self) -> int:
220+
"""
221+
:returns: 0 if a slot is available now, or an int of seconds until the next slot is free
222+
"""
223+
try:
224+
return max(
225+
ceil(
226+
(
227+
self.slot_available_datetime -
228+
datetime.now(timezone.utc)
229+
).total_seconds()
230+
),
231+
0
232+
)
233+
except TypeError:
234+
# Can't subtract from None, which means slot is available now
235+
return 0
236+
207237
def search(self, feature_type, regex=False):
208238
"""Search for something."""
209239
raise NotImplementedError()

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@
2020
"Topic :: Utilities",
2121
],
2222
install_requires=["requests>=2.3.0", "geojson>=1.0.9", "shapely>=1.6.4"],
23-
extras_require={"test": ["pytest"]},
23+
extras_require={"test": ["pytest", "requests-mock[fixture]"]},
2424
)

0 commit comments

Comments
 (0)