Skip to content

Instantly share code, notes, and snippets.

@aanari
Created September 7, 2014 19:50
Show Gist options
  • Save aanari/05cda4cf30ff1022b79c to your computer and use it in GitHub Desktop.
Save aanari/05cda4cf30ff1022b79c to your computer and use it in GitHub Desktop.
Cute Puppy Finder
#!/usr/local/bin/python
import mailer
import petfinder
import sys
api = petfinder.PetFinderClient(api_key='', api_secret='')
POODLE = 'Poodle'
LAB = 'Labrador Retriever'
GOLDEN = 'Golden Retriever'
LABRADOODLE = frozenset([LAB, POODLE])
GOLDENDOODLE = frozenset([GOLDEN, POODLE])
GMAIL_USER = sys.argv[1]
GMAIL_PASS = sys.argv[2]
body = '<h2>Your Doggie Daily Digest:<h2><div><hr>'
try:
for pet in api.pet_find(
animal='dog', location='boulder,co', output='basic', count=1000, age='baby',
):
if (pet['contact']['state'] != 'CO'):
continue
breeds = frozenset(pet['breeds'])
if ((len(breeds) == 1 and (POODLE in breeds or GOLDEN in breeds))
or (LABRADOODLE.issubset(breeds) or GOLDENDOODLE.issubset(breeds))
and pet['photos']):
link = 'https://www.petfinder.com/petdetail/' + pet['id']
body += '<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td align="center">'
body += '<h3><a href="' + link + '">' + pet['name'] + '</a></h3>'
body += '<p><a href="' + link + '"><img alt="dog image" src="' + pet['photos'][0]['url'] + '"/></a></p>'
body += '<p>' + '/'.join(pet['breeds']) + ' in ' + pet['contact']['city'] + ', ' + pet['contact']['state'] + '</p>'
body += '</td></tr></table>'
if pet['description']:
body += '<p><blockquote>"' + pet['description'][0:400] + '..."</blockquote></p>'
body += '<hr>'
except:
'Finished paging through 2,000 dogs'
body += '</div></br></br></br>---</br><b><3 Ali</b>'
message = mailer.Message(From='ali@anari.me', To='ali@anari.me')
message.Subject = "Dogs to your Inbox"
message.Html = body
sender = mailer.Mailer('smtp.gmail.com', 587, True, GMAIL_USER, GMAIL_PASS)
sender.send(message)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment