systemdate.py 1.2 KB

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