Skip to main content
Tom Casavant Tom Casavant

OHGO Wrapper

One of the problems I have with a lot of my Open Source projects is the code tends to be difficult to use in other projects because the classes end up blending into each other until it makes zero sense to pull out any of the code. So, for a project I'm working on I made concerted effort to abstract the code enough to be useful to other people.

This is a wrapper for the Ohio Department of Transportation's OHGO API. The API is a JSON REST API that provides access to traffic cameras, weather sensors, incidents, closures, and delays in the state of Ohio. I found a fantastic guide that goes through the basic process of organizing a wrapper. And I was able to turn it into a useful package that I published on pypi.

Getting started with the wrapper is simple, for example this is how you grab images from a traffic camera (after you install via pip):

from ohgo import OHGOClient

client = OHGOClient('your-api-key')
cameras = client.get_cameras() # -> Returns a list of first 500 cameras in Ohio, pass in a QueryParams object with page_all=True to get all cameras

# Or if you prefer to get a specific group of cameras we can filter it further
from ohgo.models import QueryParams
from ohgo.types import Region
params = QueryParams(region=Region.COLUMBUS) # -> Returns a list of cameras in Columbus
cameras = client.get_cameras(params)

# Now we can get the image from the camera
camera = cameras[0]
image = client.get_images(camera) # -> Returns a list of PIL images from the camera

Something I didn't know before this, is that we can overload functions in python3 (so they behave differently depending on the arguments passed in). So, I used that to make the get_image and get_images functions behave differently depending on if you pass in a Camera, CameraView, or a DigitalSign object.

That guide also led me to the Quicktype website which lets you pass in JSON, and it will generate a Python class for you (or nearly any other language) that matches the provided JSON.

I also wanted to build a small demo for the wrapper, so I made a Mastodon api compatible bot that posts a random traffic camera image every hour which you can find here: @ohgo@tomkahe.com

OHGO Wrapper Source Code

OHGO Wrapper PyPi

OHGO Mastodon Bot Source Code

Webmentions

2 Likes

Victoria (K8VSY) (she/her) Kevin Bauer

7 Retweets

Tom Casavant Programming Feed Journalism & Comment Feed Tech Cyborg Ben Keith ???? Tom Casavant Tom

These are webmentions via the IndieWeb and webmention.io. Mention this post from your site: