Skip to content

Commit 4061233

Browse files
authored
Reduce Unnecessary API Requests (#296) (#297)
1 parent 0609ec5 commit 4061233

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

SRT/srt.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,10 @@ def _search_train(
300300
# Note: updated api returns subarray of all trains,
301301
# therefore, to retrieve all trains, retry unless there are no more trains
302302
while trains:
303+
# Break if the last train's departure time is over the time_limit
304+
if time_limit and trains[-1].dep_time > time_limit:
305+
break
306+
303307
last_dep_time = datetime.strptime(trains[-1].dep_time, "%H%M%S")
304308
next_dep_time = last_dep_time + timedelta(seconds=1)
305309
data["dptTm"] = next_dep_time.strftime("%H%M%S")

0 commit comments

Comments
 (0)