Toronto City Hall API
WARNING: I provide no guarantees on the docs being entirely up-to-date. Please don't spend more than a few minutes getting it to work without speaking with me. I'm on the Freenode IRC network as "patcon". [Sign into IRC]
Set up the
Run the Toronto scraper to populate the
pupa update ca_on_toronto
Follow these steps:
bundle install bundle exec rackup
You should now be able to access the API at
This API is Swagger-compliant. With the service running, the base URL will redirect to the docs:
There are 20 results per page, and you may paginate by adding the page query string.
No guarantees of stability while the API is labelled as
A relatively up-to-date demo API is running at:
It is using data scraped from my in-progress improvements to the Toronto OCD dataset:
The Swagger docs can be viewed here:
There are a few wonderful resources related to the current hosted OCD API. I'm very appreciative of the prior art, but am interested in what I consider the more RESTful approach of APIs built on Grape.
- Open Civic Data API
Clean scrape to Heroku database
cd path/to/this/app # Set the local DATABASE_URL envvar to that of the Heroku DB heroku config --shell | grep DATABASE_URL | source /dev/stdin cd path/to/scrapers-ca # Get Toronto-specific listing of division IDs, and set envvar for usage wget https://gist.githubusercontent.com/patcon/2aecb6dae0a87c405bea/raw/25badea7220d7ddc4c80eb578683d10efce7c086/country-ca-toronto.csv OCD_DIVISION_CSV=country-ca-toronto.csv export DATABASE_URL OCD_DIVISION_CSV # WARNING: This will drop all databases in the Heroku app database. pupa dbinit --reset ca # Run all Toronto scrapers, or optionally run specific scrapers pupa update ca_on_toronto # [scraper1 scraper2, ...] # Unset envvars to make sure we're not acting on Heroku DB later unset DATABASE_URL OCD_DIVISION_CSV
We are using Heroku Pipelines for deployment.
- Code is auto-deployed from
masterto the staging app.
- Code is promoted on-demand from the staging app to the production app.
- Staging and production have their own databases.
- Review apps are automatically created for each pull request from a branch in the main repo (ie. not forks). These apps are connected to the staging database. [Example]
The above process only migrates code. To migrate the database from staging to production:
bundle exec rake tocityhall:migrate_stage_to_prod
Warning: This is a destructive action on production database. It will prompt for confirmation.
See the contributors graph.