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 None:
  8. cache = False
  9. super(Systemdate, self).__init__(cache=cache, **kwargs)
  10. # local time and date
  11. hour = time.strftime("%H") # Hour (24-hour clock) as a decimal number [00,23].
  12. minute = time.strftime("%M") # Minute as a decimal number [00,59].
  13. weekday = time.strftime("%w") # Weekday as a decimal number [0(Sunday),6].
  14. day_month = time.strftime("%d") # Day of the month as a decimal number [01,31].
  15. month = time.strftime("%m") # Month as a decimal number [01,12].
  16. year = time.strftime("%Y") # Year with century as a decimal number. E.g: 2016
  17. message = {
  18. "hours": hour,
  19. "minutes": minute,
  20. "weekday": weekday,
  21. "month": month,
  22. "day_month": day_month,
  23. "year": year
  24. }
  25. self.say(message)