def get_weather_forecast(lat,lon): import requests import time import datetime from datetime import date ##API_URL = 'https://api.darksky.net/forecast/a95ec1c3f1b53bb58c9e3d33b8a8972d/'+str(lat)+','+str(lon)+'?exclude=currently,minutely,hourly,flags' print([lat, lon]) API_URL = 'https://api.openweathermap.org//data/3.0/onecall?lon=' + str(lon) + '&lat=' +str(lat) + '&exclude=current,minutely,hourly&appid=bc0ae827a8cb9f1a628cf6fe2104ca74' resp = requests.get(API_URL) x = resp.json() print('forecast weather') print(x) all_weather_data = {} try: daily_data = x["daily"] i = 0 for key_data in daily_data: #print('k_data') print(key_data) time = key_data["dt"] single_weather_data = {} #print(time) try: single_weather_data["summary"] = key_data["weather"][0]["description"] except: single_weather_data["summary"] = "Summary Not Available" try: single_weather_data["precimax"] = key_data["precipIntensityMax"] except: single_weather_data["precimax"] = "Not Available" try: single_weather_data["precimaxtime"] = key_data["precipIntensityMaxTime"] except: single_weather_data["precimaxtime"] = "Not Available" try: single_weather_data["preciprob"] = round(float(key_data["pop"])*100,0) except: single_weather_data["preciprob"] = "Not Available" try: single_weather_data["temphigh"] = round((float(key_data["temp"]["max"]) - 273.15),2) except: single_weather_data["temphigh"] = "Not Available" try: single_weather_data["temphightime"] = key_data["temperatureHighTime"] except: single_weather_data["temphightime"] = "Not Available" try: single_weather_data["templow"] = round((float(key_data["temp"]["min"]) - 273.15),2) except: single_weather_data["templow"] = "Not Available" try: single_weather_data["templowtime"] = key_data["temperatureLowTime"] except: single_weather_data["templowtime"] = "Not Available" try: single_weather_data["cloudcover"] = key_data["clouds"] except: single_weather_data["cloudcover"] = "Not Available" all_weather_data[time]=single_weather_data #print('full data') #print(all_weather_data) return all_weather_data except: return all_weather_data # all_weather_data = {} # try: # daily_data = x["daily"]["data"] # i = 0 # for key_data in daily_data: # #print('k_data') # #print(key_data) # time = key_data["time"] # single_weather_data = {} # #print(time) # try: # single_weather_data["summary"] = key_data["summary"] # except: # single_weather_data["summary"] = "Summary Not Available" # try: # single_weather_data["precimax"] = key_data["precipIntensityMax"] # except: # single_weather_data["precimax"] = "Not Available" # try: # single_weather_data["precimaxtime"] = key_data["precipIntensityMaxTime"] # except: # single_weather_data["precimaxtime"] = "Not Available" # try: # single_weather_data["preciprob"] = key_data["precipProbability"] # except: # single_weather_data["preciprob"] = "Not Available" # try: # single_weather_data["temphigh"] = key_data["temperatureHigh"] # except: # single_weather_data["temphigh"] = "Not Available" # try: # single_weather_data["temphightime"] = key_data["temperatureHighTime"] # except: # single_weather_data["temphightime"] = "Not Available" # try: # single_weather_data["templow"] = key_data["temperatureLow"] # except: # single_weather_data["templow"] = "Not Available" # try: # single_weather_data["templowtime"] = key_data["temperatureLowTime"] # except: # single_weather_data["templowtime"] = "Not Available" # try: # single_weather_data["cloudcover"] = key_data["cloudCover"] # except: # single_weather_data["cloudcover"] = "Not Available" # all_weather_data[time]=single_weather_data # #print('full data') # #print(all_weather_data) # return all_weather_data # except: # return all_weather_data