File tree Expand file tree Collapse file tree 1 file changed +18
-3
lines changed Expand file tree Collapse file tree 1 file changed +18
-3
lines changed Original file line number Diff line number Diff line change 44# See LICENSE.txt for the full license text.
55
66import csv
7- from typing import Union
87import json
98import logging
109import re
1110from datetime import datetime
1211from io import StringIO
12+ from math import ceil
13+ from typing import Optional
1314
1415import geojson
1516import 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 ()
You can’t perform that action at this time.
0 commit comments