import telebot
from pprint import pprint
import pymysql.cursors
import json
import decimal
from time import sleep
from datetime import datetime, timedelta
from multiprocessing import Pool, TimeoutError
import tqdm
connection1 = pymysql.connect(host='127.0.0.1',
user='root',
password='pass',
charset='utf8',
db='db',
cursorclass=pymysql.cursors.DictCursor,
autocommit=True)
with connection1.cursor() as cursor1:
sql = "SELECT * FROM telegram_subscriptions WHERE chat_id IS NOT NULL AND bot_id = 1"
cursor1.execute(sql)
users = cursor1.fetchall()
if len(users):
def processInput(user):
BOT_TOKEN = "------------------------------"
bot = telebot.TeleBot(BOT_TOKEN)
connection2 = pymysql.connect(host='127.0.0.1',
user='root',
password='pass',
charset='utf8',
db='db',
cursorclass=pymysql.cursors.DictCursor,
autocommit=True)
with connection2.cursor() as cursor:
sql = "SELECT * FROM table WHERE uid = %s AND activated > 0 AND sended = 0"
cursor.execute(sql, (user['uid']))
results = cursor.fetchall()
# pprint(results)
ids = []
for res in results:
# Обработка данных из базы
.......
.......
........
bot.send_message(user['chat_id'], msg)
ids.append(str(res['id']))
ids = ','.join(ids)
if ids != "":
sql = """UPDATE table SET sended = UNIX_TIMESTAMP() WHERE id IN ({ids})""".format(ids=ids)
cursor.execute(sql)
pool = Pool(processes=10)
for _ in tqdm.tqdm(pool.imap_unordered(processInput, users), total=len(users)):
pass
Только вот что с этим делать не пойму
При этом отсылать сообщения-то он начинает, т.е. бот не забанен