Advertisement
SharkyEXE

Untitled

Jan 13th, 2019
369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.37 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. _("Февраля"),
  11. _("Марта"),
  12. _("Апреля"),
  13. _("Мая"),
  14. _("Июня"),
  15. _("Июля"),
  16. _("Августа"),
  17. _("Сентября"),
  18. _("Октября"),
  19. _("Ноября"),
  20. _("Декабря"))
  21.  
  22. shortMONTHS = (_("Янв"),
  23. _("Фев"),
  24. _("Мар"),
  25. _("Апр"),
  26. _("Май"),
  27. _("Июн"),
  28. _("Июл"),
  29. _("Авг"),
  30. _("Сен"),
  31. _("Окт"),
  32. _("Ноя"),
  33. _("Дек"))
  34.  
  35. DAYWEEK = (_("Понедельник"),
  36. _("Вторник"),
  37. _("Среда"),
  38. _("Четверг"),
  39. _("Пятница"),
  40. _("Суббота"),
  41. _("Воскресенье"))
  42.  
  43. shortDAYWEEK = (_("Пнд"),
  44. _("Втр"),
  45. _("Срд"),
  46. _("Чтв"),
  47. _("Птн"),
  48. _("Сбт"),
  49. _("Вск"))
  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>1} д{}' . 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. x = self.fmt_string
  181. spos = x.find('%')
  182. x = x.replace('%A',_(DAYWEEK[t.tm_wday]))
  183. x = x.replace('%B',_(MONTHS[t.tm_mon-1]))
  184. x = x.replace('%a',_(shortDAYWEEK[t.tm_wday]))
  185. x = x.replace('%b',_(shortMONTHS[t.tm_mon-1]))
  186. if spos > 0:
  187. s1 = x[:spos]
  188. s2 = strftime(x[spos:], t)
  189. return str(s1+s2)
  190. else:
  191. return strftime(x, t)
  192. elif self.type == self.PERMANENTCLOCK:
  193. #d = _('%H:%M:%S\n%d.%m.%Y\n%A')
  194. return _(strftime("%H:%M:%S",t)) + "\n" + strftime("%d.%m.%Y",t) + "\n" + DAYWEEK[t.tm_wday]
  195. #d = _('%H:%M:%S\n%B\n%A')
  196. #return _(strftime("%H:%M:%S",t)) + "\n" + MONTHS[t[1]-1] + "\n" + DAYWEEK[t[1]+1]
  197. #return _(strftime('%H:%M:%S\n%B\n%A',t))
  198. #return _(strftime("%H:%M:%S",t)) + "\n" + MONTHS[t.tm_mon-1] + "\n" + DAYWEEK[t.tm_wday]
  199. #d = _('%H:%M:%S\n%b\n%a')
  200. #return _(strftime("%H:%M:%S",t)) + "\n" + shortMONTHS[t[1]-1] + "\n" + shortDAYWEEK[t[1]+1]
  201. #return _(strftime('%H:%M:%S\n%b\n%a',t))
  202. #return _(strftime("%H:%M:%S",t)) + "\n" + shortMONTHS[t.tm_mon-1] + "\n" + shortDAYWEEK[t.tm_wday]
  203. else:
  204. return '???'
  205. return strftime(d, t)
  206.  
  207. text = property(getText)
  208. # okay decompyling /tmp/ClockToText.pyo
  209. # decompiled 1 files: 1 okay, 0 failed, 0 verify failed
  210. # 2018.06.23 09:02:35 EAT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement