Skip to content

Instantly share code, notes, and snippets.

@cnmcgrath
Created February 10, 2015 04:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cnmcgrath/4696fbab38e9b8b893ef to your computer and use it in GitHub Desktop.
Save cnmcgrath/4696fbab38e9b8b893ef to your computer and use it in GitHub Desktop.
# Scrapes www.thefuckingweather.com
from bs4 import BeautifulSoup as soup
import urllib2
import json
import argparse
from bottle import route, run, template
#sets param. for the zipcode ie. http://YOUR_IP/ZIPCODE
@route('/<name>')
def index(name):
parser = argparse.ArgumentParser()
parser.add_argument("-z", "--zipcode", help="ZipCode")
args = parser.parse_args()
url = "http://thefuckingweather.com?where="+name
response = urllib2.urlopen(url).read()
site = soup(response)
temperature = site.find('span', class_='temperature').string
flavor = site.find('p', class_='flavor').string
remark = site.find('p', class_='remark').string
#every now and then the scraper doesn't get the little phrase generated by the website. Not sure why.
#this handles the failure case
if (flavor == None): flavor = "Lol, you're screwed."
o_json = json.dumps({'temp':temperature,'wit':flavor,'remark':remark})
return template(o_json)
#hosts the script on my computer. change the IP address to something you would like
run(host='192.168.1.24', port='80')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment