import requests


"""
Explanation: Grade: 7 / 7
End of explanation
"""


#https://api.forecast.io/forecast/APIKEY/LATITUDE,LONGITUDE,TIME
response = requests.get('https://api.forecast.io/forecast/4da699cf85f9706ce50848a7e59591b7/12.971599,77.594563')
data = response.json()
#print(data)
#print(data.keys())
print("Bangalore is in", data['timezone'], "timezone")
timezone_find = data.keys()
#find representation

print("The longitude is", data['longitude'], "The latitude is", data['latitude'])

"""
Explanation: 1 Make a request from the Forecast.io API for where you were born (or lived, or want to visit!)
Tip: Once you've imported the JSON into a variable, check the timezone's name to make sure it seems like it got the right part of the world!
Tip 2: How is north vs. south and east vs. west latitude/longitude represented? Is it the normal North/South/East/West?
End of explanation
"""


response = requests.get('https://api.forecast.io/forecast/4da699cf85f9706ce50848a7e59591b7/40.712784,-74.005941, 2016-06-08T09:00:46-0400')
data = response.json()
#print(data.keys())
print("The current windspeed at New York is", data['currently']['windSpeed'])


# TA-COMMENT: You want to compare apparentTemperature to another value here... It may feel colder! Or the same. 

#print(data['currently']) - find how much warmer
print("It is",data['currently']['apparentTemperature'], "warmer it feels than it actually is")

"""
Explanation: 2. What's the current wind speed? How much warmer does it feel than it actually is?
End of explanation
"""


response = requests.get('https://api.forecast.io/forecast/4da699cf85f9706ce50848a7e59591b7/40.712784,-74.005941, 2016-06-08T09:00:46-0400')
data = response.json()
#print(data.keys())
#print(data['daily']['data'])

now_moon = data['daily']['data']
for i in now_moon:
    print("The visibility of moon today in New York is", i['moonPhase'], "and is in the middle of new moon phase and the first quarter moon")



"""
Explanation: 3. Moon Visible in New York
The first daily forecast is the forecast for today. For the place you decided on up above, how much of the moon is currently visible?
End of explanation
"""


response = requests.get('https://api.forecast.io/forecast/4da699cf85f9706ce50848a7e59591b7/40.712784,-74.005941, 2016-06-08T09:00:46-0400')
data = response.json()
TemMax = data['daily']['data']
for i in TemMax:
    tem_diff = i['temperatureMax'] - i['temperatureMin']
    print("The temparature difference for today approximately is", round(tem_diff))

"""
Explanation: 4. What's the difference between the high and low temperatures for today?
End of explanation
"""


response = requests.get('https://api.forecast.io/forecast/4da699cf85f9706ce50848a7e59591b7/40.712784,-74.005941')
data = response.json()
temp = data['daily']['data']
#print(temp)
count = 0
for i in temp:
    count = count+1
    print("The high temperature for the day", count, "is", i['temperatureMax'], "and the low temperature is", i['temperatureMin'])
    if float(i['temperatureMin']) < 40:
        print("it's a cold weather")
    elif (float(i['temperatureMin']) > 40) & (float(i['temperatureMin']) < 60):
        print("It's a warm day!")
    else:
        print("It's very hot weather")
    

"""
Explanation: 5. Next Week's Prediction
Loop through the daily forecast, printing out the next week's worth of predictions. I'd like to know the high temperature for each day, and whether it's hot, warm, or cold, based on what temperatures you think are hot, warm or cold.
End of explanation
"""


response = requests.get('https://api.forecast.io/forecast/4da699cf85f9706ce50848a7e59591b7/25.761680,-80.191790, 2016-06-09T12:01:00-0400')
data = response.json()
#print(data['hourly']['data'])
Tem = data['hourly']['data']
count = 0
for i in Tem:
    count = count +1
    print("The temperature in Miami, Florida on 9th June in the", count, "hour is", i['temperature'])
    if float(i['cloudCover']) > 0.5:
        print("and is cloudy")

"""
Explanation: 6.Weather in Florida
What's the weather looking like for the rest of today in Miami, Florida? I'd like to know the temperature for every hour, and if it's going to have cloud cover of more than 0.5 say "{temperature} and cloudy" instead of just the temperature.
End of explanation
"""


response = requests.get('https://api.forecast.io/forecast/4da699cf85f9706ce50848a7e59591b7/40.771133,-73.974187, 1980-12-25T12:01:00-0400')
data = response.json()
Temp = data['currently']['temperature']
print("The temperature in Central Park, NY on the Christmas Day of 1980 was", Temp)

response = requests.get('https://api.forecast.io/forecast/4da699cf85f9706ce50848a7e59591b7/40.771133,-73.974187, 1990-12-25T12:01:00-0400')
data = response.json()
Temp = data['currently']['temperature']
print("The temperature in Central Park, NY on the Christmas Day of 1990 was", Temp)

response = requests.get('https://api.forecast.io/forecast/4da699cf85f9706ce50848a7e59591b7/40.771133,-73.974187, 2000-12-25T12:01:00-0400')
data = response.json()
Temp = data['currently']['temperature']
print("The temperature in Central Park, NY on the Christmas Day of 2000 was", Temp)

"""
Explanation: 7. Temperature in Central Park
What was the temperature in Central Park on Christmas Day, 1980? How about 1990? 2000?
End of explanation
"""


