Skip to content

Commit c32d582

Browse files
committed
move printout inside try block. remove sleeps. remove close().
1 parent 0a772cf commit c32d582

File tree

1 file changed

+28
-30
lines changed

1 file changed

+28
-30
lines changed

examples/wifi/expanded/requests_wifi_api_queuetimes.py

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"""Queue-Times.com API Example"""
55

66
import os
7-
import time
87

98
import adafruit_connection_manager
109
import wifi
@@ -55,34 +54,33 @@ def time_calc(input_time):
5554
try:
5655
with requests.get(url=QTIMES_SOURCE) as qtimes_response:
5756
qtimes_json = qtimes_response.json()
57+
58+
print(" | ✅ Queue-Times JSON\n")
59+
DEBUG_QTIMES = False
60+
if DEBUG_QTIMES:
61+
print("Full API GET URL: ", QTIMES_SOURCE)
62+
print(qtimes_json)
63+
64+
# Poll Once and end script
65+
for land in qtimes_json["lands"]:
66+
qtimes_lands = str(land["name"])
67+
print(f" | Land: {qtimes_lands}")
68+
69+
# Loop through each ride in the land
70+
for ride in land["rides"]:
71+
qtimes_rides = str(ride["name"])
72+
qtimes_queuetime = str(ride["wait_time"])
73+
qtimes_isopen = str(ride["is_open"])
74+
75+
print(f" | | Ride: {qtimes_rides}")
76+
print(f" | | Queue Time: {qtimes_queuetime} Minutes")
77+
if qtimes_isopen == "False":
78+
print(" | | Status: Closed\n")
79+
elif qtimes_isopen == "True":
80+
print(" | | Status: Open\n")
81+
else:
82+
print(" | | Status: Unknown\n")
83+
84+
5885
except ConnectionError as e:
5986
print("Connection Error:", e)
60-
print(" | ✅ Queue-Times JSON\n")
61-
DEBUG_QTIMES = False
62-
if DEBUG_QTIMES:
63-
print("Full API GET URL: ", QTIMES_SOURCE)
64-
print(qtimes_json)
65-
qtimes_response.close()
66-
67-
# Poll Once and end script
68-
for land in qtimes_json["lands"]:
69-
qtimes_lands = str(land["name"])
70-
print(f" | Land: {qtimes_lands}")
71-
time.sleep(1)
72-
73-
# Loop through each ride in the land
74-
for ride in land["rides"]:
75-
qtimes_rides = str(ride["name"])
76-
qtimes_queuetime = str(ride["wait_time"])
77-
qtimes_isopen = str(ride["is_open"])
78-
79-
print(f" | | Ride: {qtimes_rides}")
80-
print(f" | | Queue Time: {qtimes_queuetime} Minutes")
81-
if qtimes_isopen == "False":
82-
print(" | | Status: Closed\n")
83-
elif qtimes_isopen == "True":
84-
print(" | | Status: Open\n")
85-
else:
86-
print(" | | Status: Unknown\n")
87-
88-
time.sleep(1) # delay between list items

0 commit comments

Comments
 (0)