Json class dict store in variables
Posted: Mon Sep 11, 2017 10:26 pm
Hi there,
my name's Marcello from italy and i'm a newbie of python. I try to make a weather station with esp8266 ssd1306 and dht22. My scope is to get value from request json weatherunderground and store in variables. I'm going crazy because i get the data from weather underground (class dict) but i don't know how to store value in variables:
Here is my code:
import urequests
r = urequests.get("http://api.wunderground.com/api/my.api/ ... cisco.json").json() #getting data
print(type(r)) #give me class dict
print (r)
{'response': {'termsofService': 'http://www.wunderground.com/weather/api/d/terms.html', 'features': {'conditions': 1}, 'version': '0.1'}, 'current_observation': {'visibility_mi': '10.0', 'feelslike_string': '83 F (28 C)', 'precip_1hr_metric': ' 0', 'observation_epoch': '1505160367', 'dewpoint_c': 15, 'wind_degrees': 121, 'local_tz_offset': '-0700', 'dewpoint_f': 59, 'wind_string': 'From the ESE at 2.0 MPH Gusting to 6.0 MPH', 'wind_gust_mph': '6.0', 'forecast_url': 'http://www.wunderground.com/US/CA/San_Francisco.html', 'history_url': 'http://www.wunderground.com/weatherstat ... CASANFR131', 'ob_url': 'http://www.wunderground.com/cgi-bin/fin ... 122.408005', 'observation_time': 'Last Updated on September 11, 1:06 PM PDT', 'pressure_trend': '0', 'wind_dir': 'ESE', 'wind_mph': 2.0, 'wind_gust_kph': '9.7', 'precip_today_string': '0.00 in (0 mm)', 'display_location': {'wmo': '99999', 'elevation': '60.0', 'city': 'San Francisco', 'longitude': '-122.41999817', 'magic': '1', 'country_iso3166': 'US', 'state': 'CA', 'zip': '94102', 'latitude': '37.77999878', 'country': 'US', 'state_name': 'California', 'full': 'San Francisco, CA'}, 'heat_index_c': 28, 'local_time_rfc822': 'Mon, 11 Sep 2017 13:06:32 -0700', 'image': {'title': 'Weather Underground', 'url': 'http://icons.wxug.com/graphics/wu2/logo_130x80.png', 'link': 'http://www.wunderground.com'}, 'icon_url': 'http://icons.wxug.com/i/c/k/partlycloudy.gif', 'estimated': {}, 'heat_index_f': 83, 'local_tz_short': 'PDT', 'heat_index_string': '83 F (28 C)', 'pressure_mb': '1012', 'visibility_km': '16.1', 'relative_humidity': '44%', 'precip_1hr_string': '0.00 in ( 0 mm)', 'windchill_f': 'NA', 'solarradiation': '972', 'wind_kph': 3.2, 'temperature_string': '83.0 F (28.3 C)', 'precip_today_metric': '0', 'windchill_c': 'NA', 'local_tz_long': 'America/Los_Angeles', 'station_id': 'KCASANFR131', 'icon': 'partlycloudy', 'observation_time_rfc822': 'Mon, 11 Sep 2017 13:06:07 -0700', 'nowcast': '', 'pressure_in': '29.88', 'UV': '4.7', 'dewpoint_string': '59 F (15 C)', 'local_epoch': '1505160392', 'observation_location': {'country': 'US', 'longitude': '-122.408005', 'state': 'California', 'city': 'SOMA, San Francisco', 'elevation': '23 ft', 'country_iso3166': 'US', 'full': 'SOMA, San Francisco, California', 'latitude': '37.778488'}, 'temp_f': 83.0, 'temp_c': 28.3, 'precip_today_in': '0.00', 'feelslike_c': '28', 'precip_1hr_in': '0.00', 'windchill_string': 'NA', 'feelslike_f': '83', 'weather': 'Partly Cloudy'}}
I don't know how getting determinate value to store in variables.
Thank you for all your support
B.R
Marcello
my name's Marcello from italy and i'm a newbie of python. I try to make a weather station with esp8266 ssd1306 and dht22. My scope is to get value from request json weatherunderground and store in variables. I'm going crazy because i get the data from weather underground (class dict) but i don't know how to store value in variables:
Here is my code:
import urequests
r = urequests.get("http://api.wunderground.com/api/my.api/ ... cisco.json").json() #getting data
print(type(r)) #give me class dict
print (r)
{'response': {'termsofService': 'http://www.wunderground.com/weather/api/d/terms.html', 'features': {'conditions': 1}, 'version': '0.1'}, 'current_observation': {'visibility_mi': '10.0', 'feelslike_string': '83 F (28 C)', 'precip_1hr_metric': ' 0', 'observation_epoch': '1505160367', 'dewpoint_c': 15, 'wind_degrees': 121, 'local_tz_offset': '-0700', 'dewpoint_f': 59, 'wind_string': 'From the ESE at 2.0 MPH Gusting to 6.0 MPH', 'wind_gust_mph': '6.0', 'forecast_url': 'http://www.wunderground.com/US/CA/San_Francisco.html', 'history_url': 'http://www.wunderground.com/weatherstat ... CASANFR131', 'ob_url': 'http://www.wunderground.com/cgi-bin/fin ... 122.408005', 'observation_time': 'Last Updated on September 11, 1:06 PM PDT', 'pressure_trend': '0', 'wind_dir': 'ESE', 'wind_mph': 2.0, 'wind_gust_kph': '9.7', 'precip_today_string': '0.00 in (0 mm)', 'display_location': {'wmo': '99999', 'elevation': '60.0', 'city': 'San Francisco', 'longitude': '-122.41999817', 'magic': '1', 'country_iso3166': 'US', 'state': 'CA', 'zip': '94102', 'latitude': '37.77999878', 'country': 'US', 'state_name': 'California', 'full': 'San Francisco, CA'}, 'heat_index_c': 28, 'local_time_rfc822': 'Mon, 11 Sep 2017 13:06:32 -0700', 'image': {'title': 'Weather Underground', 'url': 'http://icons.wxug.com/graphics/wu2/logo_130x80.png', 'link': 'http://www.wunderground.com'}, 'icon_url': 'http://icons.wxug.com/i/c/k/partlycloudy.gif', 'estimated': {}, 'heat_index_f': 83, 'local_tz_short': 'PDT', 'heat_index_string': '83 F (28 C)', 'pressure_mb': '1012', 'visibility_km': '16.1', 'relative_humidity': '44%', 'precip_1hr_string': '0.00 in ( 0 mm)', 'windchill_f': 'NA', 'solarradiation': '972', 'wind_kph': 3.2, 'temperature_string': '83.0 F (28.3 C)', 'precip_today_metric': '0', 'windchill_c': 'NA', 'local_tz_long': 'America/Los_Angeles', 'station_id': 'KCASANFR131', 'icon': 'partlycloudy', 'observation_time_rfc822': 'Mon, 11 Sep 2017 13:06:07 -0700', 'nowcast': '', 'pressure_in': '29.88', 'UV': '4.7', 'dewpoint_string': '59 F (15 C)', 'local_epoch': '1505160392', 'observation_location': {'country': 'US', 'longitude': '-122.408005', 'state': 'California', 'city': 'SOMA, San Francisco', 'elevation': '23 ft', 'country_iso3166': 'US', 'full': 'SOMA, San Francisco, California', 'latitude': '37.778488'}, 'temp_f': 83.0, 'temp_c': 28.3, 'precip_today_in': '0.00', 'feelslike_c': '28', 'precip_1hr_in': '0.00', 'windchill_string': 'NA', 'feelslike_f': '83', 'weather': 'Partly Cloudy'}}
I don't know how getting determinate value to store in variables.
Thank you for all your support
B.R
Marcello