Skip to content

Commit bef9ff0

Browse files
committed
Split into datetime and countdown properties
1 parent 0953bc8 commit bef9ff0

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

overpass/api.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
# See LICENSE.txt for the full license text.
55

66
import csv
7-
from typing import Union
87
import json
98
import logging
109
import re
1110
from datetime import datetime
1211
from io import StringIO
12+
from math import ceil
13+
from typing import Optional
1314

1415
import geojson
1516
import requests
@@ -202,14 +203,28 @@ def slots_running(self) -> tuple:
202203
return self._api_status()["running_slots"]
203204

204205
@property
205-
def next_slot_available(self) -> Union(None, datetime):
206+
def slot_available_datetime(self) -> Optional[datetime]:
206207
"""
207-
:returns: None if a slot is available now, or a datetime for when the next slot is free
208+
:returns: None if a slot is available now (no wait needed) or a datetime representing when the next slot will become available
208209
"""
209210
if self.slots_available:
210211
return None
211212
return min(self.slots_running + self.slots_waiting)
212213

214+
@property
215+
def slot_available_countdown(self) -> int:
216+
"""
217+
:returns: 0 if a slot is available now, or an int of seconds until the next slot is free
218+
"""
219+
try:
220+
return ceil(
221+
(self.slot_available_datetime -
222+
datetime.now().astimezone()).total_seconds()
223+
)
224+
except TypeError:
225+
# Can't subtract from None, which means slot is available now
226+
return 0
227+
213228
def search(self, feature_type, regex=False):
214229
"""Search for something."""
215230
raise NotImplementedError()

0 commit comments

Comments
 (0)