systemdate.py 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. import time
  2. from core.NeuronModule import NeuronModule
  3. class Systemdate(NeuronModule):
  4. def __init__(self, **kwargs):
  5. # get the cache if set by the user, if not, set it to false as it is not necessary
  6. cache = kwargs.get('cache', None)
  7. if cache is not None:
  8. kwargs["cache"] = cache
  9. else:
  10. kwargs["cache"] = False
  11. super(Systemdate, self).__init__(**kwargs)
  12. # local time and date
  13. hour = time.strftime("%H") # Hour (24-hour clock) as a decimal number [00,23].
  14. minute = time.strftime("%M") # Minute as a decimal number [00,59].
  15. weekday = time.strftime("%w") # Weekday as a decimal number [0(Sunday),6].
  16. day_month = time.strftime("%d") # Day of the month as a decimal number [01,31].
  17. month = time.strftime("%m") # Month as a decimal number [01,12].
  18. year = time.strftime("%Y") # Year with century as a decimal number. E.g: 2016
  19. message = {
  20. "hours": hour,
  21. "minutes": minute,
  22. "weekday": weekday,
  23. "month": month,
  24. "day_month": day_month,
  25. "year": year
  26. }
  27. self.say(message)