#@TecOEd
#Weather Parser reader from Yahoo

#!/usr/bin/env python

#http://developer.yahoo.com/weather/developers api overview

import time
import feedparser
import os

#while Ture:
#pulls all the data down
rss_link ='http://weather.yahooapis.com/forecastrss?w=44418&u=c' #add your area code
d = feedparser.parse(rss_link)


#Parse data in various elements
location = d.feed.yweather_location #returns the location data from yahoo
city =location['city'] # looks for the city from the location data

atmosphere = d.feed.yweather_atmosphere # returns the atmosphere data from yahoo 
humidity = atmosphere['humidity']

astronomy = d.feed.yweather_astronomy #returns astronomy data from yahoo
sunrise = astronomy['sunrise'] #returns the sunrise time
sunset = astronomy['sunset'] #returns the sunset time

wind = d.feed.yweather_wind
chill = wind['chill']

#summary
summary = d.entries[0].summary # returns the full weather summary for area code
#but requires spliting 
#print summary

#prints weather elements
print""
time.sleep(1)
print "Weather for "+city
print " "
time.sleep(2)
print "Sunrise for "+city, sunrise
print ""
time.sleep(2)
print "Sunset for "+city, sunset
print""
time.sleep(2)
print "Humidity for "+city, humidity
print""
time.sleep(2)
print "Wind chill for "+city, chill, "degrees"
time.sleep(2)
print""

print "Weather provided by @TeCoEd"

weather = ["Weather for "+city,
           "Sunrise for "+city, sunrise,
           "Sunset for "+city, sunset,
           "Humidity for "+city, humidity,
           "Wind chill for "+city, chill, "degrees",
           "Weather provided by @TeCoEd"] #adds weather status to a list called weather

def write_to_file(x): 
        file = open("Weather_Summary.txt", "w") #Weather_Summary is the name of the text file the program writes to
        for i in weather:
            file.write(i+'\n')
        file.close()
        print ""
        print "Your Weather data has been stored"

write_to_file(weather)

time.sleep(5)
print "good bye"
time.sleep(2)
   
