I'm attempting to get datetime information from the JSON I'm pulling from the API in a quick script I'm making in Python. When I go to grab the 'dt'
value, it gives me such lovely results as 1628313960
or 1628314020
. If you're a robot out there, I'm sure this is pretty good info, but to a human like me, I'm looking for something a little more along the lines of:
"dt_txt": "2020-08-05 13:00:00"
as it is showed in the API docs. I'm not able to find this key anywhere in the dictionary I've pulled. It does not appear to be there. This is what I've tried:
import requests, json
def get_48_hour_weather_data():
url = f'https://api.openweathermap.org/data/2.5/onecall?lat={lat}&lon={lon}&appid={api_key}&units=metric'
response = requests.get(url)
weather_data = json.loads(response.text)
return weather_data
Does anybody know how to either:
- Convert something like
1628313960
to something like"2020-08-05 13:00:00"
- Get the
'dt_txt'
value associated with the rest of thisweather_data
Either solution would be great, and any help is appreciated! Thank you for reading, and I hope this an easy answer or reputation point for you if you are reading.