Advertisement
SharkyEXE

Untitled

Jan 2nd, 2019
373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.07 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. # 2018.06.23 09:02:31 EAT
  3. #Embedded file name: /usr/lib/enigma2/python/Components/Converter/ClockToText.py
  4. from Converter import Converter
  5. from time import localtime, strftime, mktime, time
  6. from Components.Element import cached
  7. from datetime import date, datetime
  8.  
  9. MONTHS = (_('Январь'),
  10. _('February'),
  11. _('March'),
  12. _('April'),
  13. _('May'),
  14. _('June'),
  15. _('July'),
  16. _('August'),
  17. _('September'),
  18. _('October'),
  19. _('November'),
  20. _('December'))
  21.  
  22. shortMONTHS = (_('Jan'),
  23. _('Feb'),
  24. _('Mar'),
  25. _('Apr'),
  26. _('May'),
  27. _('Jun'),
  28. _('Jul'),
  29. _('Aug'),
  30. _('Sep'),
  31. _('Oct'),
  32. _('Nov'),
  33. _('Dec'))
  34.  
  35. DAYWEEK = (_('Понедельник'),
  36. _('Вторник'),
  37. _('Среда'),
  38. _('Четверг'),
  39. _('Пятница'),
  40. _('Суббота'),
  41. _('Воскресенье'))
  42.  
  43. shortDAYWEEK = (_('Mon'),
  44. _('Tue'),
  45. _('Wed'),
  46. _('Thu'),
  47. _('Fri'),
  48. _('Sat'),
  49. _('Sun'))
  50.  
  51. class ClockToText(Converter, object):
  52. DEFAULT = 0
  53. WITH_SECONDS = 1
  54. IN_MINUTES = 2
  55. DATE = 3
  56. FORMAT = 4
  57. AS_LENGTH = 5
  58. TIMESTAMP = 6
  59. FULL = 7
  60. SHORT_DATE = 8
  61. LONG_DATE = 9
  62. VFD = 10
  63. AS_LENGTHHOURS = 11
  64. AS_LENGTHSECONDS = 12
  65. FULL_DATE = 13
  66. NEWYEAR = 14
  67. PERMANENTCLOCK = 15
  68.  
  69. # add: date, date as string, weekday, ...
  70. # (whatever you need!)
  71.  
  72. def __init__(self, type):
  73. Converter.__init__(self, type)
  74. self.fix = ''
  75. if ';' in type:
  76. type, self.fix = type.split(';')
  77. if type == 'WithSeconds':
  78. self.type = self.WITH_SECONDS
  79. elif type == 'InMinutes':
  80. self.type = self.IN_MINUTES
  81. elif type == 'Date':
  82. self.type = self.DATE
  83. elif type == 'AsLength':
  84. self.type = self.AS_LENGTH
  85. elif type == 'AsLengthHours':
  86. self.type = self.AS_LENGTHHOURS
  87. elif type == 'AsLengthSeconds':
  88. self.type = self.AS_LENGTHSECONDS
  89. elif type == 'Timestamp':
  90. self.type = self.TIMESTAMP
  91. elif type == 'Full':
  92. self.type = self.FULL
  93. elif type == 'ShortDate':
  94. self.type = self.SHORT_DATE
  95. elif type == 'LongDate':
  96. self.type = self.LONG_DATE
  97. elif type == 'FullDate':
  98. self.type = self.FULL_DATE
  99. elif type == 'VFD':
  100. self.type = self.VFD
  101. elif type == 'NewYear':
  102. self.type = self.NEWYEAR
  103. elif type == 'PermanentClock':
  104. self.type = self.PERMANENTCLOCK
  105. #elif 'Format' in type:
  106. elif str(type).find('Format') != -1:
  107. self.type = self.FORMAT
  108. self.fmt_string = type[7:]
  109. else:
  110. self.type = self.DEFAULT
  111.  
  112. @cached
  113. def getText(self):
  114. time = self.source.time
  115. if time is None:
  116. return ''
  117.  
  118. def fix_space(string):
  119. if 'Proportional' in self.fix and t.tm_hour < 10:
  120. return ' ' + string
  121. if 'NoSpace' in self.fix:
  122. return string.lstrip(' ')
  123. return string
  124.  
  125. def get_variant(amount, variants):
  126. cases = [2, 0, 1, 1, 1, 2]
  127. return variants[2 if (amount % 100 > 4 and amount % 100 < 20) else cases[min(amount % 10, 5)]]
  128.  
  129. # handle durations
  130. if self.type == self.IN_MINUTES:
  131. return ngettext('%d Min', '%d Mins', time / 60) % (time / 60)
  132. if self.type == self.AS_LENGTH:
  133. if time < 0:
  134. return ''
  135. return '%d:%02d' % (time / 60, time % 60)
  136. if self.type == self.AS_LENGTHHOURS:
  137. if time < 0:
  138. return ''
  139. return '%d:%02d' % (time / 3600, time / 60 % 60)
  140. if self.type == self.AS_LENGTHSECONDS:
  141. if time < 0:
  142. return ''
  143. return '%d:%02d:%02d' % (time / 3600, time / 60 % 60, time % 60)
  144. if self.type == self.TIMESTAMP:
  145. return str(time)
  146. t = localtime(time)
  147. td = datetime(date.today().year + 1, 1, 1) - datetime.fromtimestamp(mktime(t))
  148. days, hours, minutes, seconds = td.days, td.seconds // 3600, td.seconds // 60 % 60, td.seconds % 60
  149. if self.type == self.WITH_SECONDS:
  150. return fix_space(_('%02d:%02d:%02d') % (t.tm_hour, t.tm_min, t.tm_sec))
  151. if self.type == self.NEWYEAR:
  152. title_text = _("До Нового , %s Года , остал%s :\n") % ( date.today().year + 1, get_variant(days, ('ся', 'ось', 'ось')))
  153. text = [
  154. '{:0>2} д{}' . format(days, get_variant(days, ('ень', 'ня', 'ней'))),
  155. '{:0>2} час{}' . format(hours, get_variant(hours, ('', 'а', 'ов'))),
  156. '{:0>2} минут{}' . format(minutes, get_variant(minutes, ('а', 'ы', ''))),
  157. '{:0>2} секунд{}' . format(seconds, get_variant(seconds, ('а', 'ы', '')))
  158. ]
  159. return title_text + ' ; '.join(text)
  160. if self.type == self.DEFAULT:
  161. return fix_space(_('%02d:%02d') % (t.tm_hour, t.tm_min))
  162. if self.type == self.DATE:
  163. d = _('%A')
  164. #Пример ниже
  165. #Wednesday, 2 Январь, 2019 year.
  166. #return _(strftime("%A",t)) + ", " + str(t[2]) + " " + MONTHS[t[1]-1] + ", " + str(t[0]) + _(" year.")
  167. #return _(strftime("%A",t))
  168. elif self.type == self.FULL:
  169. d = _('%d.%m.%Y')
  170. elif self.type == self.SHORT_DATE:
  171. d = _('%a %d/%m')
  172. elif self.type == self.LONG_DATE:
  173. d = _('%A %d %B')
  174. elif self.type == self.FULL_DATE:
  175. d = _('%a %d %B %Y')
  176. elif self.type == self.VFD:
  177. d = _('%H:%M %d/%m')
  178. elif self.type == self.FORMAT:
  179. #d = self.fmt_string
  180. spos = self.fmt_string.find('%')
  181. self.fmt_string = self.fmt_string.replace('%A',_(DAYWEEK[t.tm_wday]))
  182. self.fmt_string = self.fmt_string.replace('%B',_(MONTHS[t.tm_mon-1]))
  183. self.fmt_string = self.fmt_string.replace('%a',_(shortDAYWEEK[t.tm_wday]))
  184. self.fmt_string = self.fmt_string.replace('%b',_(shortMONTHS[t.tm_mon-1]))
  185. if spos > 0:
  186. s1 = self.fmt_string[:spos]
  187. s2 = strftime(self.fmt_string[spos:], t)
  188. return str(s1+s2)
  189. else:
  190. return strftime(self.fmt_string, t)
  191. elif self.type == self.PERMANENTCLOCK:
  192. #d = _('%H:%M:%S\n%d.%m.%Y\n%A')
  193. #d = _('%H:%M:%S\n%B\n%A')
  194. #return _(strftime("%H:%M:%S",t)) + "\n" + MONTHS[t[1]-1] + "\n" + DAYWEEK[t[1]+1]
  195. return _(strftime('%H:%M:%S\n%B\n%A',t))
  196. #d = _('%H:%M:%S\n%b\n%a')
  197. #return _(strftime("%H:%M:%S",t)) + "\n" + shortMONTHS[t[1]-1] + "\n" + shortDAYWEEK[t[1]+1]
  198. #return _(strftime('%H:%M:%S\n%b\n%a',t))
  199. else:
  200. return '???'
  201. return strftime(d, t)
  202.  
  203. text = property(getText)
  204. # okay decompyling /tmp/ClockToText.pyo
  205. # decompiled 1 files: 1 okay, 0 failed, 0 verify failed
  206. # 2018.06.23 09:02:35 EAT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement