Skip to content

ryanrudes/traffic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

New York State Department of Transportation API

PyPI download month PyPI - Status PyPI GitHub

Installation

pip install nysdotapi

Authentication

  1. Visit the 511 NY website and create a new account
  2. Login to your account and request an API key here

Example

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