Python RGB Matrix games and animations https://www.xythobuz.de/ledmatrix_v2.html
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #!/usr/bin/env python3
  2. # ----------------------------------------------------------------------------
  3. # "THE BEER-WARE LICENSE" (Revision 42):
  4. # <xythobuz@xythobuz.de> wrote this file. As long as you retain this notice
  5. # you can do whatever you want with this stuff. If we meet some day, and you
  6. # think this stuff is worth it, you can buy me a beer in return. Thomas Buck
  7. # ----------------------------------------------------------------------------
  8. import time
  9. import requests
  10. class CheckHTTP:
  11. def __init__(self, u, r = 600.0):
  12. self.url = u
  13. self.refresh = r
  14. self.successScreen = None
  15. self.failScreen = None
  16. self.restart()
  17. def success(self, s):
  18. self.successScreen = s
  19. def fail(self, f):
  20. self.failScreen = f
  21. def restart(self):
  22. self.start = time.time()
  23. self.response = None
  24. self.request()
  25. if self.successScreen != None:
  26. self.successScreen.restart()
  27. if self.failScreen != None:
  28. self.failScreen.restart()
  29. def request(self):
  30. if (self.response == None) or ((time.time() - self.start) >= self.refresh):
  31. self.start = time.time()
  32. try:
  33. r = requests.get(self.url)
  34. self.response = r.ok
  35. except:
  36. self.response = False
  37. def finished(self):
  38. self.request()
  39. if self.response:
  40. return self.successScreen.finished()
  41. else:
  42. return self.failScreen.finished()
  43. def draw(self):
  44. self.request()
  45. if self.response:
  46. return self.successScreen.draw()
  47. else:
  48. return self.failScreen.draw()
  49. if __name__ == "__main__":
  50. from draw import ScrollText
  51. import util
  52. t = util.getTarget()
  53. d = CheckHTTP("http://xythobuz.de")
  54. d.success(ScrollText(t, "Success"))
  55. d.fail(ScrollText(t, "Failure"))
  56. t.debug_loop(d.draw)