56 lines
1.9 KiB
Python
56 lines
1.9 KiB
Python
|
|
import pprint
|
|
|
|
weatherData = {'coord': {'lon': -72.5949, 'lat': 42.1726},
|
|
'weather': [{'id': 801, 'main': 'Clouds', 'description': 'few clouds', 'icon': '02n'}],
|
|
'base': 'stations',
|
|
'main': {'temp': 285.11, 'feels_like': 283.25, 'temp_min': 282.18, 'temp_max': 286.21,
|
|
'pressure': 1015, 'humidity': 34},
|
|
'visibility': 10000,
|
|
'wind': {'speed': 3.6, 'deg': 160},
|
|
'clouds': {'all': 20},
|
|
'dt': 1649723543,
|
|
'sys': {'type': 1, 'id': 3598, 'country': 'US', 'sunrise': 1649672158,
|
|
'sunset': 1649719584},
|
|
'timezone': -14400,
|
|
'id': 4933002,
|
|
'name': 'Chicopee',
|
|
'cod': 200}
|
|
|
|
pp = pprint.PrettyPrinter(indent=4)
|
|
|
|
pp.pprint(weatherData)
|
|
|
|
print("\n")
|
|
|
|
print("\ncoord",weatherData['coord'])
|
|
print("weather: ",weatherData['weather'])
|
|
print("base: ",weatherData['base'])
|
|
print("main: ",weatherData['main'])
|
|
print("wind: ",weatherData['wind'])
|
|
print("visibility: ",weatherData['visibility'])
|
|
print("clouds: ",weatherData['clouds'])
|
|
print("dt: ",weatherData['dt'])
|
|
print("sys: ",weatherData['sys'])
|
|
print("timezone: ",weatherData['timezone'])
|
|
print("id: ",weatherData['id'])
|
|
print("name: ",weatherData['name'])
|
|
print("cod: ",weatherData['cod'])
|
|
|
|
print("Keys")
|
|
for key in weatherData.keys():
|
|
print(key)
|
|
|
|
print("Keys and Data")
|
|
for key in weatherData.keys():
|
|
print(f"{key:10s}: {weatherData[key]}")
|
|
|
|
# Accessing Latitude and Longitude
|
|
print(f"Latitude,Longitude = {weatherData['coord']['lat']},{weatherData['coord']['lon']}")
|
|
|
|
# Accessing Latitude and Longitude (Alternate method)
|
|
# Assign the coord dictionary to a new variable. Now use the new variable to manipulate the data.
|
|
coordinates = weatherData['coord']
|
|
print(f"Latitude,Longitude = {coordinates['lat']},{coordinates['lon']}")
|
|
|