Skip to content

Instantly share code, notes, and snippets.

@stucka
Last active December 20, 2015 05:48
Show Gist options
  • Save stucka/6080601 to your computer and use it in GitHub Desktop.
Save stucka/6080601 to your computer and use it in GitHub Desktop.
Get nicely formatted local weather. National Weather Service has less-good forecasts available in uppercase via FTP, but not these.
#!/home/mstucka/bin/python
# New Perl-esque version!
#!/home/mstucka/bin/python
#from bs4 import BeautifulSoup
#import requests
#full_url = 'http://forecast.weather.gov/MapClick.php?lat=32.8406946&lon=-83.6324022&site=all&smap=1&searchresult=Macon%2C%20GA%2C%20USA#.UfA_Q23fLTr'
#ul = (BeautifulSoup(requests.get(full_url).text)).find_all("ul", class_="point-forecast-7-day")
#li = str(ul[0].find_all('li')[0])
#print li[(li.rfind("/span")+6):(li.rfind("/li")-1)].strip()
from bs4 import BeautifulSoup
import requests
full_url = 'http://forecast.weather.gov/MapClick.php?lat=32.8406946&lon=-83.6324022&site=all&smap=1&searchresult=Macon%2C%20GA%2C%20USA#.UfA_Q23fLTr'
r = requests.get(full_url)
html = r.text
soup = BeautifulSoup(html)
ul = soup.find_all("ul", class_="point-forecast-7-day")
li = str(ul[0].find_all('li')[0])
listart = li.rfind("/span") + 6
liend= li.rfind("/li") -1
forecast=li[listart:liend].strip()
print forecast
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment