Python RGB Matrix games and animations https://www.xythobuz.de/ledmatrix_v2.html
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

weather.py 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/usr/bin/env python3
  2. from pyowm.owm import OWM
  3. from pyowm.utils.config import get_default_config
  4. import time
  5. api_key = "7de9d39fd4476f811000ceecbbe69376"
  6. class WeatherScreen:
  7. def __init__(self, gui, latitude = 47.7174, longitude = 9.3924, language = "de", refresh = 600, width = 32, height = 32):
  8. self.gui = gui
  9. self.latitude = latitude
  10. self.longitude = longitude
  11. self.language = language
  12. self.refresh = refresh
  13. self.width = width
  14. self.height = height
  15. self.lastTime = time.time()
  16. self.data = ""
  17. self.fetchData()
  18. def fetchData(self):
  19. config_dict = get_default_config()
  20. config_dict['language'] = self.language
  21. owm = OWM(api_key, config_dict)
  22. mgr = owm.weather_manager()
  23. observation = mgr.weather_at_place("Tuttlingen, DE")
  24. print(observation.weather.rain)
  25. print(observation.weather.snow)
  26. print(observation.weather.wind)
  27. print(observation.weather.humidity)
  28. print(observation.weather.pressure)
  29. print(observation.weather.temperature)
  30. print(observation.weather.clouds)
  31. print(observation.weather.status)
  32. print(observation.weather.detailed_status)
  33. print(observation.weather.weather_icon_name)
  34. print(observation.weather.precipitation_probability)
  35. #self.data = mgr.one_call(lat=self.latitude, lon=self.longitude)
  36. #print(self.data.forecast_hourly[0].wind().get("speed", 0))
  37. def draw(self):
  38. if (time.time() - self.lastTime) > self.refresh:
  39. self.fetchData()
  40. self.lastTime = time.time()
  41. # TODO text location
  42. # TODO text data
  43. def finished(self):
  44. return True
  45. def restart(self):
  46. pass
  47. if __name__ == "__main__":
  48. import platform
  49. t = None
  50. if platform.machine() == "armv7l":
  51. from pi import PiMatrix
  52. t = PiMatrix()
  53. else:
  54. from test import TestGUI
  55. t = TestGUI()
  56. s = WeatherScreen(t)
  57. s.draw()
  58. t.debug_loop(s.draw)