Created
April 19, 2011 05:51
-
-
Save feltnerm/926882 to your computer and use it in GitHub Desktop.
Tell me the f*ckin weather!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/python | |
# -*- coding: utf-8 -*- | |
''' | |
Created on Jul 16, 2010 | |
@author: mark | |
''' | |
import sys, string, pprint | |
from datetime import datetime | |
from thefuckingweather import LocationError, get_weather, DEGREE_SYMBOL | |
def get_and_parse_weather(zip_code): | |
try: | |
weather_data = get_weather(zip_code) | |
return weather_data | |
except LocationError: | |
pass | |
def show_data(weather_data): | |
current = weather_data["current"] | |
forecast = weather_data["forecast"] | |
todays_forecast = forecast[0] | |
tomorrows_forecast = forecast[1] | |
location = weather_data["location"] | |
weather = current["weather"] | |
weather = weather[0] | |
# begin constructing output | |
clean_weather = weather # don't wanna cuss | |
clean_weather_idx = string.find(clean_weather,'FUCK') | |
if clean_weather_idx == -1: | |
print clean_weather_idx | |
pass | |
else: | |
clean_weather = string.replace(clean_weather, 'FUCK', 'F*CK') | |
now = "%s (%r°) '%s!' %s" % (location, current["temperature"], clean_weather.strip(""), current["remark"]) | |
current = "%s - %s - Hi %r° Lo %r°" % (todays_forecast["day"], todays_forecast["weather"], todays_forecast["high"], todays_forecast["low"]) | |
next = "%s - %s - Hi %r° Lo %r°" % (tomorrows_forecast["day"], tomorrows_forecast["weather"], tomorrows_forecast["high"], tomorrows_forecast["low"]) | |
print now | |
print current | |
print next | |
def main(): | |
if len(sys.argv) != 2: | |
print 'Usage: the_fing_weather <zip>' | |
sys.exit(0) | |
zip_code = sys.argv[1] | |
weather_data = get_and_parse_weather(zip_code) | |
show_data(weather_data) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment