· 5 years ago · Nov 25, 2020, 10:42 AM
1import vkquick as vq
2import aiosqlite
3import asyncio
4
5
6create_table_sql = """
7CREATE TABLE IF NOT EXISTS questions (
8 id INTEGER PRIMARY KEY AUTOINCREMENT,
9 post_url TEXT NOT NULL,
10 count INTEGER,
11 date TEXT NOT NULL
12)
13"""
14set_data_sql = 'INSERT INTO questions (post_url, count, date) VALUES ("test", 50, "test2")'
15get_data_sql = "SELECT * FROM questions"
16
17
18async def log(database, sql):
19 database.row_factory = aiosqlite.Row
20 cursor = await database.cursor()
21 await cursor.execute(get_data_sql)
22 result = await cursor.fetchall()
23 print(result)
24
25async def execute(database, sql):
26 cursor = await database.cursor()
27 await cursor.execute(sql)
28 await database.commit()
29
30async def main(file):
31 async with aiosqlite.connect(file) as conn:
32 # save conn somewher
33 await asyncio.gather(execute(conn, create_table_sql))
34 await asyncio.gather(execute(conn, set_data_sql))
35 await asyncio.gather(log(conn, get_data_sql))
36
37
38@vq.Command(
39 prefixes=["/"],
40 names=["questions"]
41)
42async def questions(ctx: vq.Context):
43 """
44 Даёт список заданий
45 """
46 await main('database.db')
47 #await ctx.message.reply(text, disable_mentions=True)
48
49