# -*- coding: utf-8 -*- # 2018.06.23 09:02:31 EAT #Embedded file name: /usr/lib/enigma2/python/Components/Converter/ClockToText.py from Converter import Converter from time import localtime, strftime, mktime, time from Components.Element import cached from datetime import date, datetime MONTHS = (_("Января"), _("Февраля"), _("Марта"), _("Апреля"), _("Мая"), _("Июня"), _("Июля"), _("Августа"), _("Сентября"), _("Октября"), _("Ноября"), _("Декабря")) shortMONTHS = (_("Янв"), _("Фев"), _("Мар"), _("Апр"), _("Май"), _("Июн"), _("Июл"), _("Авг"), _("Сен"), _("Окт"), _("Ноя"), _("Дек")) DAYWEEK = (_("Понедельник"), _("Вторник"), _("Среда"), _("Четверг"), _("Пятница"), _("Суббота"), _("Воскресенье")) shortDAYWEEK = (_("Пнд"), _("Втр"), _("Срд"), _("Чтв"), _("Птн"), _("Сбт"), _("Вск")) class ClockToText(Converter, object): DEFAULT = 0 WITH_SECONDS = 1 IN_MINUTES = 2 DATE = 3 FORMAT = 4 AS_LENGTH = 5 TIMESTAMP = 6 FULL = 7 SHORT_DATE = 8 LONG_DATE = 9 VFD = 10 AS_LENGTHHOURS = 11 AS_LENGTHSECONDS = 12 FULL_DATE = 13 NEWYEAR = 14 PERMANENTCLOCK = 15 # add: date, date as string, weekday, ... # (whatever you need!) def __init__(self, type): Converter.__init__(self, type) self.fix = '' if ';' in type: type, self.fix = type.split(';') if type == 'WithSeconds': self.type = self.WITH_SECONDS elif type == 'InMinutes': self.type = self.IN_MINUTES elif type == 'Date': self.type = self.DATE elif type == 'AsLength': self.type = self.AS_LENGTH elif type == 'AsLengthHours': self.type = self.AS_LENGTHHOURS elif type == 'AsLengthSeconds': self.type = self.AS_LENGTHSECONDS elif type == 'Timestamp': self.type = self.TIMESTAMP elif type == 'Full': self.type = self.FULL elif type == 'ShortDate': self.type = self.SHORT_DATE elif type == 'LongDate': self.type = self.LONG_DATE elif type == 'FullDate': self.type = self.FULL_DATE elif type == 'VFD': self.type = self.VFD elif type == 'NewYear': self.type = self.NEWYEAR elif type == 'PermanentClock': self.type = self.PERMANENTCLOCK #elif 'Format' in type: elif str(type).find('Format') != -1: self.type = self.FORMAT self.fmt_string = type[7:] else: self.type = self.DEFAULT @cached def getText(self): time = self.source.time if time is None: return '' def fix_space(string): if 'Proportional' in self.fix and t.tm_hour < 10: return ' ' + string if 'NoSpace' in self.fix: return string.lstrip(' ') return string def get_variant(amount, variants): cases = [2, 0, 1, 1, 1, 2] return variants[2 if (amount % 100 > 4 and amount % 100 < 20) else cases[min(amount % 10, 5)]] # handle durations if self.type == self.IN_MINUTES: return ngettext('%d Min', '%d Mins', time / 60) % (time / 60) if self.type == self.AS_LENGTH: if time < 0: return '' return '%d:%02d' % (time / 60, time % 60) if self.type == self.AS_LENGTHHOURS: if time < 0: return '' return '%d:%02d' % (time / 3600, time / 60 % 60) if self.type == self.AS_LENGTHSECONDS: if time < 0: return '' return '%d:%02d:%02d' % (time / 3600, time / 60 % 60, time % 60) if self.type == self.TIMESTAMP: return str(time) t = localtime(time) td = datetime(date.today().year + 1, 1, 1) - datetime.fromtimestamp(mktime(t)) days, hours, minutes, seconds = td.days, td.seconds // 3600, td.seconds // 60 % 60, td.seconds % 60 if self.type == self.WITH_SECONDS: return fix_space(_('%02d:%02d:%02d') % (t.tm_hour, t.tm_min, t.tm_sec)) if self.type == self.NEWYEAR: title_text = _("До Нового , %s Года , остал%s :\n") % ( date.today().year + 1, get_variant(days, ('ся', 'ось', 'ось'))) text = [ '{:0>1} д{}' . format(days, get_variant(days, ('ень', 'ня', 'ней'))), '{:0>2} час{}' . format(hours, get_variant(hours, ('', 'а', 'ов'))), '{:0>2} минут{}' . format(minutes, get_variant(minutes, ('а', 'ы', ''))), '{:0>2} секунд{}' . format(seconds, get_variant(seconds, ('а', 'ы', ''))) ] return title_text + ' ; '.join(text) if self.type == self.DEFAULT: return fix_space(_('%02d:%02d') % (t.tm_hour, t.tm_min)) if self.type == self.DATE: d = _('%A') #Пример ниже #Wednesday, 2 Январь, 2019 year. #return _(strftime("%A",t)) + ", " + str(t[2]) + " " + MONTHS[t[1]-1] + ", " + str(t[0]) + _(" year.") #return _(strftime("%A",t)) elif self.type == self.FULL: d = _('%d.%m.%Y') elif self.type == self.SHORT_DATE: d = _('%a %d/%m') elif self.type == self.LONG_DATE: d = _('%A %d %B') elif self.type == self.FULL_DATE: d = _('%a %d %B %Y') elif self.type == self.VFD: d = _('%H:%M %d/%m') elif self.type == self.FORMAT: #d = self.fmt_string x = self.fmt_string spos = x.find('%') x = x.replace('%A',_(DAYWEEK[t.tm_wday])) x = x.replace('%B',_(MONTHS[t.tm_mon-1])) x = x.replace('%a',_(shortDAYWEEK[t.tm_wday])) x = x.replace('%b',_(shortMONTHS[t.tm_mon-1])) if spos > 0: s1 = x[:spos] s2 = strftime(x[spos:], t) return str(s1+s2) else: return strftime(x, t) elif self.type == self.PERMANENTCLOCK: #d = _('%H:%M:%S\n%d.%m.%Y\n%A') return _(strftime("%H:%M:%S",t)) + "\n" + strftime("%d.%m.%Y",t) + "\n" + DAYWEEK[t.tm_wday] #d = _('%H:%M:%S\n%B\n%A') #return _(strftime("%H:%M:%S",t)) + "\n" + MONTHS[t[1]-1] + "\n" + DAYWEEK[t[1]+1] #return _(strftime('%H:%M:%S\n%B\n%A',t)) #return _(strftime("%H:%M:%S",t)) + "\n" + MONTHS[t.tm_mon-1] + "\n" + DAYWEEK[t.tm_wday] #d = _('%H:%M:%S\n%b\n%a') #return _(strftime("%H:%M:%S",t)) + "\n" + shortMONTHS[t[1]-1] + "\n" + shortDAYWEEK[t[1]+1] #return _(strftime('%H:%M:%S\n%b\n%a',t)) #return _(strftime("%H:%M:%S",t)) + "\n" + shortMONTHS[t.tm_mon-1] + "\n" + shortDAYWEEK[t.tm_wday] else: return '???' return strftime(d, t) text = property(getText) # okay decompyling /tmp/ClockToText.pyo # decompiled 1 files: 1 okay, 0 failed, 0 verify failed # 2018.06.23 09:02:35 EAT