-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.py
70 lines (59 loc) · 2 KB
/
db.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python3.6
import sqlite3
import settings
class User():
def __init__(self, db):
self.db = db
def addDB(self, user, chat_id):
self.user = user
self.chat_id = chat_id
connect = sqlite3.connect(self.db)
cursor = connect.cursor()
cursor.execute("""INSERT INTO users VALUES ('%s','%d')""" % (self.user,self.chat_id))
connect.commit()
def delete_userdb(self, chat_id):
# Удаление пользователя телеграм в базе, получаемые от обработчика команды "remove'
self.chatid = chat_id
connect = sqlite3.connect(self.db)
cursor = connect.cursor()
sql = "DELETE FROM users WHERE chatId=?"
cursor.execute(sql,[self.chatid])
connect.commit()
def infoUserDB(self):
#Получаем все из table user
connect = sqlite3.connect(self.db)
cursor = connect.cursor()
sql = "SELECT * FROM users"
cursor.execute(sql)
rows = cursor.fetchall()
return rows
class Dictionary():
file = open(settings.TMP_FILE)
txt = file.readlines()
count = int(txt[0])
def __init__(self, db):
self.db = db
def set_phr(self):
connect = sqlite3.connect(self.db)
cursor = connect.cursor()
sql = "SELECT * FROM dictionary WHERE id=?"
row = []
for i in range(self.count, self.count + 5):
ids = i
cursor.execute(sql, [ids])
rows = cursor.fetchall()
# self.count += 5
wr = open(settings.TMP_FILE, "w")
new_num = str(i + 1)
wr.write(new_num)
wr.close()
for k in rows:
row.append(k)
return row
def send_mess(self,bot):
user = User(settings.DB_NAME)
users = user.infoUserDB()
temp = self.set_phr()
for chatid in users:
for tem in temp:
bot.send_message(chatid[1],tem[1])