API - pętla

0

Cześć, ostatnio za pomocą Raspberry Pi zrobiłem wyświetlanie danych pogodowych z wykorzystaniem OpenWeather API.
Skrypt dodałem do automatycznego startu i kiedy podłączam malinkę do zasilania pobiera dane, ale wyświetla cały czas to samo (dane pobrane w momencie uruchomienia). Kiedy link otworzę w przeglądarce, widzę że dane uległy zmianie. Jak mam dodać pobieranie aktualnych danych co jakiś czas?

import lcddriver
import time
import datetime
import requests, json 

display = lcddriver.lcd()
complete_url = "http://api.openweathermap.org/data/2.5/weather?q=MIASTO&APPID=***UKRYTE API***" 

response = requests.get(complete_url)

x = response.json() 
  

if x["cod"] != "404": 
  

    y = x["main"] 
  
    
    current_temperature = y["temp"] 
  
 
    current_pressure = y["pressure"] 
  
    
    current_humidiy = y["humidity"] 
  


  
    
    z = x["weather"] 
  

    weather_description = z[0]["description"] 
try:
    while True:
        
        print("Wypisywanie uruchomione")
        display.lcd_display_string("Temperatura zew:",1)
        display.lcd_display_string(str(current_temperature-273.15) + " C", 2) 
        time.sleep(10)  
        display.lcd_clear()                                  
        display.lcd_display_string("Cisnienie ", 1)
        display.lcd_display_string(str(current_pressure) + " hPa",2)  
        time.sleep(10) 
        display.lcd_clear()
        display.lcd_display_string("Wilgotnosc ", 1)
        display.lcd_display_string(str(current_humidiy) + " %",2)
        time.sleep(10)                                 
        display.lcd_clear()                             
        time.sleep(1)                                   

except KeyboardInterrupt:
    print("Cleaning up!")
    display.lcd_clear()
0

Otworzyłeś link, Zapisałeś dane w jakiejś strukturze, a potem w pętli Odtwarzasz ciągle te same; to Ci wyświetla to samo.

1 użytkowników online, w tym zalogowanych: 0, gości: 1