-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtakeToken.py
More file actions
32 lines (27 loc) · 826 Bytes
/
Copy pathtakeToken.py
File metadata and controls
32 lines (27 loc) · 826 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import telebot
import config
import random
import sqlite3
bot = telebot.TeleBot(config.TOKEN)
def generate_unique_token():
existing_tokens = set()
conn = sqlite3.connect('shop.sql')
cur = conn.cursor()
cur.execute('SELECT * FROM tokens')
items = cur.fetchall()
# Получаем результат запроса
for el in items:
existing_tokens.add(int(el[4]))
cur.close()
conn.close()
available_tokens = set(range(1, 4)) - existing_tokens
if not available_tokens:
return None
return random.choice(list(available_tokens))
def delete_art(token):
conn = sqlite3.connect('shop.sql')
cur = conn.cursor()
cur.execute("DELETE FROM tokens WHERE token = ?", (token,))
conn.commit()
cur.close()
conn.close()