In [1]:
import requests
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?
In [21]:
#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
In [ ]:
In [35]:
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'])
#print(data['currently']) - find how much warmer
In [58]:
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'])
In [66]:
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))
In [88]:
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")
In [104]:
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")
In [113]:
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)
In [ ]: