Skip to content

Instantly share code, notes, and snippets.

@jamespenguin
Created July 5, 2011 17:53
Show Gist options
  • Save jamespenguin/1065409 to your computer and use it in GitHub Desktop.
Save jamespenguin/1065409 to your computer and use it in GitHub Desktop.
Fortune cookie message getter
#!/usr/bin/env python
#
# Fortune Cookie Saying Grabber
# By James Penguin (brandon.smith@gmail.com)
#
import BeautifulSoup
import urllib2
def get_fortune():
try:
page = urllib2.urlopen("http://www.fortunecookiemessage.com/")
except:
return "No fortune for you."
soup = BeautifulSoup.BeautifulSoup(page)
for tag in soup.findAll("a"):
if not tag.has_key("href") or not tag["href"].startswith("cookie"):
continue
if not len(tag.contents):
return "No fortune for you."
return tag.contents[0]
return "No fortune for you."
if __name__ == '__main__':
print get_fortune()
@leejarvis
Copy link

Yeah son!

ruby -rnokogiri -ropen-uri -e "p Nokogiri.HTML(open('http://fortunecookiemessage.com')).at('h1/a').text"

@jamespenguin
Copy link
Author

:| but does it go to my cell phone?

@leejarvis
Copy link

:(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment