pip install nysdotapi
The following code cycles through live feeds of various traffic cameras at random.
from traffic import API
import random
import cv2
api = API("<insert-api-key>")
cameras = api.get_cameras()
print("Cameras:", len(cameras))
while True:
camera = random.choice(cameras)
try:
with camera.get_stream() as stream:
title = "LIVE: " + camera.roadway if camera.roadway else "LIVE"
for i in range(100):
frame = next(stream)
cv2.imshow(title, frame)
cv2.waitKey(1)
cv2.destroyAllWindows()
except KeyboardInterrupt:
raise
except StopIteration:
pass