E
E
eternity_aa2020-05-13 20:27:58
Python
eternity_aa, 2020-05-13 20:27:58

How to truncate the list as soon as the date changes and remove the previous entries?

I get weather data from openweathermap, the length of the list is constantly changing depending on the time the service is accessed. You need to leave only three days, and remove the first and last. I'm using a free subscription
I'm a complete newbie to python, please help me

try:  
    res = requests.get("http://api.openweathermap.org/data/2.5/forecast",params={'id': city_id, 'units': 'metric','lang': 'ru', 'APPID': appid})
    data = res.json()
    forecastlist=[]
    for i in data['list']:
        forecast=i['dt_txt'],'{0:+3.0f}'.format(i['main']['temp']),i['main']['pressure'],i['main']['humidity'],i['wind']['speed']
        forecastlist.append(forecast)
    weather = np.array(forecastlist).reshape(-1, 5)


5ebc2de65eece815863031.png

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question