time.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import constants
  2. from packet import Packet
  3. class Time(object):
  4. def call(self):
  5. """Call time for insertion into a TEXT file.
  6. Returns:
  7. formatted string to use in a TEXT
  8. """
  9. return "\x13"
  10. def set(self, hour=None, minute=None):
  11. """Sets ths hour and minute of the internal clock on the sign.
  12. If the time is not specified in the arguments, the time now will be used.
  13. Args:
  14. hour: hour in 24-hour format (18 instead of 6 for 6PM)
  15. minute: minute (0 - 59)
  16. Returns:
  17. Packet object
  18. """
  19. now = datetime.datetime.today()
  20. if hour is None:
  21. hour = now.hour
  22. if minute is None:
  23. minute = now.minute
  24. packet = Packet("%s%s%02d%02d" % (constants.WRITE_SPECIAL, "\x20",
  25. hour, minute))
  26. return packet
  27. def set_format(self, format=1):
  28. """Sets the time format on the sign.
  29. Args:
  30. format: 1 - 24-hour (military) time
  31. 0 - 12-hour (standard am/pm) format
  32. Returns:
  33. Packet object
  34. """
  35. if format < 0 or format > 1:
  36. format = 1
  37. byte = (format == 0) and "S" or "M"
  38. packet = Packet("%s%s%s" % (constants.WRITE_SPECIAL, "\x27", byte))
  39. return packet