def test_locale_de(self): options = Options() options.locale_code = 'de_DE' options.use_24hour_time_format = True self.assertEqual( "Jede Minute", ExpressionDescriptor("* * * * *", options).get_description())
def test_inline_import(self): from cron_descriptor import Options, DescriptionTypeEnum, ExpressionDescriptor options = Options() options.use_24hour_time_format = True options.locale_code = self.options.locale_code ceh = ExpressionDescriptor("* * * * *", options) self.assertEqual("Every minute", ceh.get_description(DescriptionTypeEnum.FULL))
def format_poll_data(poll: Poll): options = Options() options.locale_code = "ru_RU" return (poll.question or "Нет", ("\n\t\\- " + "\n\t\\- ".join(poll.answers)) if poll.answers else "Нет", "Да" if poll.is_anonymous else "Нет", "Да" if poll.is_multiple else "Нет", str(ExpressionDescriptor(poll.schedule, options)) if poll.schedule else "Не установлено")
def test_full_import(self): from cron_descriptor.Options import Options from cron_descriptor.DescriptionTypeEnum import DescriptionTypeEnum from cron_descriptor.ExpressionDescriptor import ExpressionDescriptor options = Options() options.use_24hour_time_format = True options.locale_code = self.options.locale_code ceh = ExpressionDescriptor("* * * * *", options) self.assertEqual('Every minute', ceh.get_description(DescriptionTypeEnum.FULL))
def build_schedule_html(html_top: str = "<div>", html_bottom: str = "</div>") -> str: """Create a basic HTML table with the currently scheduled jobs. Args: html_top (str, optional): HTML to go before the table. Defaults to "<div>". html_bottom (str, optional): HTML to go at hte end of the table. Defaults to "</div>". Returns: str: HTML code. """ # Ensure scheduler is shut down, then re-add jobs and retrieve scheduled jobs from okr/scrapers/scheduler.py scheduler.setup() scheduler.scheduler.shutdown() scheduler.add_jobs() jobs_list = scheduler.scheduler.get_jobs() options = Options() options.locale_code = "de_DE" options.use_24hour_time_format = True # parse and convert job information into list table_lines = [] for job in jobs_list: cron_expression = " ".join(map(str, reversed(job.trigger.fields[1:]))) table_lines.append([ parse_job_info_method(job), get_description(cron_expression, options=options), ]) # sort list by module and reformat to a module.method format (instead of library.module.method) formatted_list = sorted(table_lines, key=itemgetter(0)) for entry in formatted_list: args_idx = entry[0].index("(") path = entry[0][:args_idx] rest = entry[0][args_idx:] path = ".".join(path.split(".")[-2:]) entry[0] = f"{path}{rest}" # convert jobs list into HTML table table_contents = tabulate( formatted_list, headers=["Aufgerufene Methode", "Zeitschema"], tablefmt="html", ) return str(html_top + table_contents + html_bottom)
def get_cron_description(self, expression): options = Options() options.locale_code = 'zh_CN' return get_description(expression, options).__str__()