import psycopg2 as ps
base = ps.connect(DATABASE_URL, sslmode='require')
cur = base.cursor()
async def main_menu (message):
cur.execute("""CREATE TABLE IF NOT EXISTS log_id(us_id INTEGER)""")
base.commit()
user_id = message.chat.id
cur.execute(f"SELECT * FROM log_id WHERE us_id = (%s);, {user_id}")
data = cur.fetchone()
if data is None:
cur.execute("INSERT INTO log_id (us_id) VALUES (%s);", (user_id,))
base.commit()
else:
pass
await bot.send_message(message.from_user.id, "Привет, {}!".format(message.from_user.first_name))
await bot.send_message(message.from_user.id, "Выбери категорию \U00002B07",
reply_markup=mainmenu_kb)
async def sendall(message: types.Message):
if message.chat.type == 'private':
if message.from_user.id == ADMIN:
text = message.text[9:]
users = cur.execute("SELECT us_id, active FROM log_id").fetchall()
for row in users:
try:
await bot.send_message(row[0], text)
if int(row[1]) != 1:
user_id = row[0]
active = row[1]
cur.execute("UPDATE log_id SET active = %s WHERE us_id = %s;", (us_id, active))(row[0], 1)
base.commit()
except:
user_id = row[0]
active = row[1]
cur.execute("UPDATE log_id SET active = %s WHERE us_id = %s;", (us_id, active))(row[0], 0)
base.commit()
await bot.send_message(message.from_user.id, "Успешная рассылка!")
user_id = message.chat.id
на user_id = message.from_user.id
cur.execute("""CREATE TABLE IF NOT EXISTS log_id(us_id INTEGER)""")
base.commit()
async def main_menu (message):
base = ps.connect(DATABASE_URL, sslmode='require')
cur = base.cursor()
user_id = message.from_user.id
cur.execute("SELECT * FROM log_id WHERE us_id = %s;", (user_id, ))
data = cur.fetchone()
if data is None:
cur.execute("INSERT INTO log_id (us_id) VALUES (%s);", (user_id, ))
base.commit()
cur.close()
else:
base.commit()
cur.close()
await bot.send_message(message.from_user.id, "Привет, {}!".format(message.from_user.first_name))
await bot.send_message(message.from_user.id, "Выбери категорию \U00002B07",
reply_markup=mainmenu_kb)