如何每 X 分钟从 openweather api 获取数据?我想使用 Raspberry Pi Zero W 在 16x2 LCD 上显示此数据。
import lcddriver
import time
import datetime
import requests, json
display = lcddriver.lcd()
complete_url = "http://api.openweathermap.org/data/2.5/weather?q=CITY&APPID=****HIDE_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:
print("Writing to display")
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: # If there is a KeyboardInterrupt (when you press ctrl+c), exit the program and cleanup
print("Cleaning up!")
display.lcd_clear()
青春有我
隔江千里
相关分类