Skip to content

Using the Oregon Department of Transportation (ODOT) CCTV API to generate a site with cameras

License

Notifications You must be signed in to change notification settings

zigsphere/odot-cameras

Repository files navigation

ODOT Road Conditions

Using the Oregon Department of Transportation (ODOT) CCTV API to generate a site with cameras.

Build Status Lint Status CodeQL

This is an experimental Flask web application that pulls from the ODOT API. The site shows various cities with the surrounding traffic cameras and incident information.

Site is live at: https://www.camsoregon.com/

To Run

In the docker-compose.yml file, set the API_KEY environment variable to your own API key. You can get one from https://apiportal.odot.state.or.us/product#product=tripcheck-api-data. Once set:

docker-compose up -d

For development, in the docker-compose.yml file, comment out the image attribute and uncomment the build: .. Then you can simply run docker-compose up --build to build the image from the included Dockerfile.

Caching

The application is currently using Redis to store the cache for the retrieved data from the ODOT API. This is done by using the Flask-Caching Python library. A cache is used to avoid hitting the API rate limit from each load of the page. Instead, the cache is stored for the time specified for HOMEPAGE_CACHE_TIMEOUT and DATA_CACHE_TIMEOUT. These can be set as environment variables for the ODOT container image within the docker-compose file. Now, when the page is loaded by several concurrent connections, the data is pulled from the Redis cache rather than performing an API call each time. You can change the cache type if desired. https://flask-caching.readthedocs.io/

Used APIs

A list of the data that can be retrieved is listed here; however, currently the CCTV inventory and incidents API are the only two used in this application.

When retrieving API credentials, you will receive two tokens. You will need them both. This application uses multiple keys to avoid the API rate limits due to the amount of data being pulled.

Weather data is pulled from https://www.weatherapi.com/. You will also need to sign up for an API token, which is free.

Environment Variables

Below are the environment variables that can be set:

- API_KEY                 # First API Key
- API_KEY_2               # Second API Key
- BROADCASTIFY_KEY        # API key to embed Broadcastify iframes on the main site
- WEATHER_API_KEY         # API key to fetch weather data https://www.weatherapi.com/
- CCTV_CACHE_TIMEOUT      # Cache for the fetched JSON of the CCTV camera inventory (default is 86400 seconds (24 hours))
- INCIDENT_CACHE_TIMEOUT  # Cache for the fetched JSON of the incident inventory (default is 900 seconds)
- HOMEPAGE_CACHE_TIMEOUT  # Cache for the rendered output (default is 30 seconds)
- REDIS_HOST              # Redis hostname (default is redis if using the included container)
- REDIS_PASSWORD          # Redis Password (default is password)

Planned Features

  • Better web frontend
  • Multi-page site for other cities with more information
  • Better error handling
  • Use Redis for cache management (Currently using python dictionaries aka SimpleCache)
  • Add local event information for each city
  • Add road & weather information for each city

road

About

Using the Oregon Department of Transportation (ODOT) CCTV API to generate a site with cameras

Resources

License

Stars

Watchers

Forks

Releases

No releases published