def datelist(start_date, end_date) : from datetime import date, timedelta as td import datetime import daily_weather as dw import pandas as pd import requests d1 = end_date #End date d2 = start_date #Start date #A DarkSky.net api key is needed to be input. status = False while status == False: apikey= str(input('Enter your Dark Sky APIkey:')) url = 'https://api.forecast.io/forecast/'+apikey+'/41.878311,-87.616342,'+datetime.date.today().isoformat()+'T00:00:00' r = requests.get(url) status = r.status_code == requests.codes.ok #Determine how many days are between the end date and start date delta= d1-d2 d = pd.DataFrame() #Create a data fame d ''' This function goes into each day in the date range, uses daily_weather.py to grab the information that is needed to run the analyses in the future, and places it in the 'd' data frame. ''' for i in range(delta.days+1) : day =d2+td(days=i) #Getting the specific day #create the datetime format needed for the darksky.net api. da =day.isoformat()+'T00:00:00' #run the daily_weather function that returns the #weather for a specific day. data = dw.daily_weather(lat= '41.878311', long='-87.616342',date=da,apikey=apikey) d.loc[i,'Date'] = day.isoformat() #Add the date to the d data frame. #Put all the weather information from dark sky onto the d dataframe for j in data : d.loc[i,j] = data.loc[0,j] #Put data frame d into 2016_weather.csv d.to_csv(d2.isoformat()+'_to_'+d1.isoformat()+'.csv',index=False) return d
#Grab the Latitude of the beach we are going to be pulling the weather for lattitude = str(df.loc[i,'lat']) #Grab the Latitude of the beach we are going to be pulling the weather for longitude = str(df.loc[i,'long']) for day in range(5) :#for each of the past 5 days at the beach/row. if day == 0: #Find the day we are grabbing the weather for d = pd.to_datetime(df.loc[i,'Full_date'],format = '%Y-%m-%d')+datetime.timedelta(days=day+1) else : #Find the day we are grabbing the weather for d = pd.to_datetime(df.loc[i,'Full_date'],format = '%Y-%m-%d')-datetime.timedelta(days=day-1) #Strip the date and time we found for d d = datetime.datetime.strptime(str(d),'%Y-%m-%d %H:%M:%S') #Grab the weather for the day weather = dw.daily_weather(lat= lattitude, long=longitude,date=d.strftime("%Y-%m-%dT%H:%M:%S"),apikey=apikey) #Fill in the weather variables needed for the day that you are predicting if day == 0 : for item in newcols_today : if item =='humidity_hour_4' : df.loc[i,item]= weather.loc[0,'4.humidity.hourly'] elif item == 'pressure_hour_0' : df.loc[i,item]= weather.loc[0,'0.pressure.hourly'] elif item == 'temperature_hour_0' : df.loc[i,item]= weather.loc[0,'0.temperature.hourly'] elif item == 'temperature_hour_1' : df.loc[i,item]= weather.loc[0,'1.temperature.hourly'] elif item == 'temperature_hour_2' : df.loc[i,item]= weather.loc[0,'2.temperature.hourly'] elif item == 'temperature_hour_3' :