Project of Becky Boone and Drew during their fellowship at Code for America in 2014.
Modified by CodeforBoston to work with the Petfinder.com API
Modified by CodeforHamptonRoads to move the shelter_id to an environment variable so one repository can be used for several cities. Also added #hashtags for breed, type, and city.
A twitter bot that pulls data from the Petfinder API and tweets out adoptable pets from the the shelter of your choosing to a twitter feed.
This is easily extendable to other shelters using petfinder.com to list their animals.
This Github Repository supports this Twitter account:
Petfinder API Docs:
bundle install
You need to sign up for a twitter API. You'll need all of the following:
- consumer_key
- consumer_secret
- access_token
- access_token_secret
- shelter_id of the shelter you want to query
To get twitter keys setup an application for your twitter account: https://dev.twitter.com/docs/auth/tokens-devtwittercom
You'll also need Petfinder keys
- petfinder_key
- petfinder_secret
To get them, first register for a Petfinder account: https://users.petfinder.com/login
Then sign up for the API keys: https://www.petfinder.com/developers/api-key
Copy template.env
and rename as .env
file to include your actual keys instead of placeholders.
The variables in this file will be automatically picked up when you run the rake task. If you would like to
specify multiple shelters to select random pets from, identify them as a comma-separated list.
Do not commit your modified .env file to anywhere public. The .env line in the .gitignore file prevents you from accidentally exposing your keys. Do not remove this line.
consumer_key=XXXXXXXXXXXXXXXXXXXXXX
consumer_secret=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
access_token=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
access_token_secret=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
petfinder_key=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
petfinder_secret=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
shelter_id=MA124
rake tweet
The tweet task is in the Rakefile, which invokes the rest of cuties.rb
.
CutiesInNorfolk and CutiesInPtown uses Heroku and the Heroku Scheduler plugin to tweet hourly.
You can use this Github repository for several Twitter account as long as you set the environment variables on the Heroku instances.
Hat tips
-
Kudos to Darius for his great guide on how to make a twitter bot.
-
And kudo to Erik for the twitter gem.