Based off of Code for America's CutePetsDenver made by Team Denver.
CutePetsDenver Twitter feed: https://twitter.com/CutePetsDenver
We've tried to make this as simple as possible. You'll be setting up a few free online accounts, connecting them together, then you'll get your very own CutePets twitter bot. Its painless and takes about an hour. Lets go.
- We'll find an animal shelter we want to help get pets adopted from.
- We'll set up a new Twitter account for these CutePets.
- We'll create a bot that regularly posts the pets pictures and info.
This service requires a credit card to get set up. This card will NOT be charged.
We're scraping info from Petharbor to make our Twitter bot.
- Search on petharbor.com for a shelter in your town.
- Find the petharbor shelter id. The shelter id can be found near the end of the url, before the pet id, when clicking on the short link for a pet through petharbor.com. i.e. the shelter id in http://www.petharbor.com/pet.asp?uaid=BRKL.A034281 is
BRKL
. - Figure out which pet types your shelter has. Do a search on petharbor.com narrowed down by your shelter. It should be
cat
dog
orothers
. - We'll need this info in a few minutes, keep it around.
First we'll make a new twitter account, then we'll set up the 'bot' side of things.
- Create a twitter account with the user name you'd like to have stream your pet tweets
- Add your phone number. If your phone number ia already attached to your personal Twitter account, you've got two options:
- Quickest way is to make a new temporary phone number using Google Voice or BurnerApp.
- Create the new twitter app on your personal accountthen transfer the API key to the new bot account here by selecting “I need to transfer an API key to another account”, filling out the form, and waiting a few days.
- Accept the confirmation email that Twitter sends you.
- Create a new twitter app.
- For Website, use the new twitter account you just made, https://twitter.com/cutepetstester or whatever
- Leave callback url blank
- Accept Developer Agreement
- Go to the Keys & Access Token tab
- Create an Access Token
- Good work so far. We're going to need all of these values soon, so keep this window open or write them down.
This is where we'll turn on a free rented computer in the sky. It will run the code that grabs the info about animals from Petharbor, then tells Twitter to tweet about them.
- Create a Heroku account
- Confirm the email they send you.
- Cick here ->
- Give your new app a unique name. Try the same name as your Twitter account.
- Now go to "Settings" and then "Reveal Config Vars"
- Enter in the Twitter values, using the variable names from .env
- Enter in the Petharbor values, using the variable names from .env
- Enter in your credit card info. You will NOT be charged.
- Click on "Manage App"
- Click on "Heroku Scheduler"
- Click on "Add new job"
- In the text box, copy and paste
rake tweet_pet
- Keep the dyno size at free. Set the frequency at daily.
- Choose the closest time to now to send your first tweet. You can check UTC time at https://www.google.com/search?q=utc+time.
- Wait for it, wait for it.
- Yeah! You did it!
Great work. Now, tell us which city you made a cutepets bot for. We do this by sending in a Pull Request with our twitter bot's name and location.
- Make a new Github Account. Choose the free account plan.
- Check out the map on the CutePets Repo
- We want to add our own point to the map. We'll need the latitude and longitude for our city. Try using Bing Maps or http://www.latlong.net/ to easily find them.
- Edit the where.geojson file using this link.
- Add in your twitter bot's name and location using the format below. Note that the negative longitude goes first. Be sure to have that comma at the very end too.
{
"type": "Feature",
"properties":
{
"twitter" : "http://twitter.com/CutePetsAdamsCo"
},
"geometry":
{
"type": "Point",
"coordinates": [ -104.871902 , 39.891651 ]
}
},
- Click "Propose Changes" at the bottom of the page.
- Click "Create Pull Request"
- That's it! Thanks!