#!/usr/bin/env python3 from telegram import Bot from db import get_conn, Subscriber from config import BOT_TOKEN, ADMIN def send_users_list(bot: Bot = None): conn = get_conn(read_only=True) if not bot: bot = Bot(BOT_TOKEN) subs = conn.root.subscribers.values() messages = [f'Count: {subs.count()}\n'] for sub in subs: # type: Subscriber msg = f'#{sub.id:<4} {sub.uid:>14} ' if sub.uid < 0: msg += str(sub.name) else: msg += f'{sub.name}' messages.append(msg) for i in range(0, len(messages), 40): bot.send_message(ADMIN, '\n'.join(messages[i:i+40]), parse_mode='html') if __name__ == '__main__': send_users_list()