Just starting out here, hopefully this is simple and someone can push me in the right direction.
- What I have is a weather API that returns a lot of data I don't need.
- I can pull the relevant information into a smaller json dict, this works
What I want to do, is set the values from the dict as variables so that everytime this runs, the variables are assigned new data
import requests import json from requests.auth import HTTPBasicAuth import datetime import time from datetime import datetime weatherString = requests.get('https://twcservice.mybluemix.net/api/weather/v1/geocode/33.40/-83.42/observations.json?language=en-US&units=e', auth=HTTPBasicAuth('user','pass')) data=weatherString.json() result = { "Hum": data['observation']['rh'], "Pressure": data['observation']['pressure'], "DewPt": data['observation']['dewPt'], "Temp": data['observation']['temp'], "Time": datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S') } final = json.dumps(result) print(final)
In short, I would like Hum, Pressure, DewPt, Temp, and Time to be variables instead of keys in a dict if that makes sense.