Esempio n. 1
0
def birthday_check():
    action_log('Scheduled job: launched birthday check')

    drs = birthdays_get()

    today = datetime.today().strftime('%d.%m')
    names = ''

    for date, name in drs:
        if date == today:
            names += '{} {}\n'.format(random.choice(happy_emoji), code(name))

    if len(names) > 0:
        text = 'Сегодня день рождения {}:\n\n{}'.format(
            'отмечает' if names.count('\n') == 1 else 'отмечают', names)
        subs_notify(my_data.list_users(for_what='morning_birthdays'), text)
Esempio n. 2
0
 def dump_file(self, message=None):
     if tokens.dumping_channel_id != '':
         msg_1 = send_file(tokens.dumping_channel_id,
                           self.file_name,
                           caption='{}: dump user db | {}'.format(
                               my_bot.name, curr_time()))
         msg_2 = send_file(tokens.dumping_channel_id,
                           config.FileLocation.bot_logs,
                           caption='{}: dump logs | {}'.format(
                               my_bot.name, curr_time()))
         if message is None:
             action_log('Scheduled job: data dumped to ' +
                        chat_info(msg_2.chat))
         else:
             my_bot.forward_message(message.chat.id, msg_1.chat.id,
                                    msg_1.message_id)
Esempio n. 3
0
def handle_updates(updates):
    if tokens.chatbase_token != '':
        for update in updates:
            ret = my_analytics.track_message(update)
            if not ret.ok:
                action_log(ret.text)
Esempio n. 4
0
# All updates handler
def handle_updates(updates):
    if tokens.chatbase_token != '':
        for update in updates:
            ret = my_analytics.track_message(update)
            if not ret.ok:
                action_log(ret.text)


if __name__ == '__main__':
    # Настройка глобальных переменных
    my_bot.set_proxy()
    my_bot.skip_pending = False
    my_bot.set_update_listener(handle_updates)
    action_log('Running bot!')

    scheduler = BackgroundScheduler()
    scheduler.add_job(my_acs.in_office_alert,
                      'interval',
                      id='in_office_alert',
                      max_instances=3,
                      seconds=30)
    scheduler.add_job(birthday.birthday_check,
                      'cron',
                      id='birthday_check',
                      replace_existing=True,
                      hour=11)
    scheduler.add_job(my_data.dump_file,
                      'cron',
                      id='dump_file',