-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBase.py
1116 lines (936 loc) · 56.3 KB
/
Base.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
import time
import sqlite3
from sqlite3 import Error
database = "/home/playps/bot/ps_unity.db"
def create_connection(db_file):
""" create a database connection to a SQLite database """
try:
conn = sqlite3.connect(db_file)
return conn
except Error as e:
with open("log.txt", 'a') as log:
log.write(str(e))
return None
def create_table(conn, create_table_sql):
""" create a table from the create_table_sql statement
:param conn: Connection object
:param create_table_sql: a CREATE TABLE statement
:return:
"""
try:
c = conn.cursor()
c.execute(create_table_sql)
except Error as e:
with open("log.txt", 'a') as log:
log.write(str(e))
"""##################################################################################################################"""
"""___________________________________________________Games table____________________________________________________"""
def add_new_game(conn, game):
"""
Add a new game in games
:param conn:
:param game: "name-must, description-must, genre-must, date-must, photo-must, price-must, links-variable
:return: games id
"""
sql = ''' INSERT INTO games (name, description, genre, date, photo, price, links)
VALUES(?,?,?,?,?,?,?) '''
cur = conn.cursor()
cur.execute(sql, game)
return cur.lastrowid
def update_game(conn, game):
"""
Update information about a game in games
:param conn:
:param game: name-must, description-must, genre-must, date-must, photo-must, price-must, links-variable, id
:return: None
"""
sql = ''' UPDATE games
SET name = ? ,
description = ? ,
genre = ? ,
date = ? ,
photo = ? ,
price = ? ,
links = ?
WHERE id = ?'''
cur = conn.cursor()
cur.execute(sql, game)
def delete_game(conn, game_id):
"""
Delete a game by game id
:param conn: Connection to the SQLite database
:param game_id: id of the task
:return:
"""
sql = 'DELETE FROM games WHERE id=?'
cur = conn.cursor()
cur.execute(sql, (game_id,))
def delete_games(conn):
"""
remove table top
:return:
"""
sql = "DROP TABLE games"
cur = conn.cursor()
cur.execute(sql)
def select_in_games(conn, needle):
"""
search in games name
:param conn:
:param needle:
:return:
"""
sql = "SELECT * FROM games WHERE name LIKE '%'||?||'%'"
cur = conn.cursor()
res = cur.execute(sql, (needle,))
return res
def select_all_games(conn):
"""
Return all rows from games
:param conn: the Connection object
:return:
"""
cur = conn.cursor()
cur.execute("SELECT * FROM games")
rows = cur.fetchall()
return rows
def select_game_name_by_id(conn, game_id):
"""
Return a game by it's id in table games
:param conn: the Connection object
:param game_id:
:return: game with id = game_id
"""
cur = conn.cursor()
cur.execute("SELECT name FROM games WHERE id=?", (game_id,))
return "ggame0" + cur.fetchone()[0]
def select_game_cost_by_id(conn, game_id):
"""
Return a game's cost by it's id in table games
:param conn: the Connection object
:param game_id:
:return: game with id = game_id
"""
cur = conn.cursor()
cur.execute("SELECT price FROM games WHERE id=?", (game_id,))
return cur.fetchone()[0]
def select_all_genres_from_games(conn):
"""
Select all available genres from Base
:param conn: the Connection object
:param:
:return: all available genres
"""
cur = conn.cursor()
cur.execute("SELECT genre FROM games")
rows = cur.fetchall()
res = []
for row in rows:
if ('genres' + row[0]) not in res:
res.append('genres' + row[0])
return res
def select_games_by_genre(conn, genre):
"""
Select all games with genre="genre"
:param conn: the Connection object
:param genre:
:return: all games witch is genre-type (in list - format sequence)
"""
cur = conn.cursor()
cur.execute("SELECT name FROM games WHERE genre=?", (genre,))
rows = cur.fetchall()
res = []
for row in rows:
res.append('ggames' + row[0])
return res
def select_game_by_name(conn, name):
"""
select game from games where name == name
:param conn:
:param name:
:return res: game with name == name or None
"""
cur = conn.cursor()
cur.execute("SELECT * FROM games WHERE name=?", (name,))
res = cur.fetchall()
return res
def select_games_by_date(conn, year):
"""
Select all games with date="year"
:param conn: the Connection object
:param year:
:return: all games that released at year
"""
cur = conn.cursor()
cur.execute("SELECT * FROM games WHERE date=?", (year,))
rows = cur.fetchall()
return rows
"""##################################################################################################################"""
"""____________________________________________________Top table_____________________________________________________"""
def add_to_top(conn, rating):
"""
Add position at top-20 table
:param conn:
:param rating:
:return: None
"""
sql = ''' INSERT INTO top (games_id)
VALUES(?) '''
cur = conn.cursor()
cur.execute(sql, (rating,))
def update_top(conn, new_pos):
"""
Update top-list in table top
:param conn:
:param new_pos: games_id, id
:return: None
"""
sql = ''' UPDATE top
SET games_id = ?
WHERE id = ?'''
cur = conn.cursor()
cur.execute(sql, new_pos)
def delete_position_top(conn, top_id):
"""
Delete a game by game id
:param conn: Connection to the SQLite database
:param top_id: id of the position
:return:
"""
sql = '''DELETE FROM top WHERE id=?'''
cur = conn.cursor()
cur.execute(sql, (top_id,))
def delete_top(conn):
"""
remove table top
:return:
"""
sql = "DROP TABLE top"
cur = conn.cursor()
cur.execute(sql)
def select_all_from_top(conn):
"""
Select all games id in top
:param conn: the Connection object
:return:
"""
cur = conn.cursor()
cur.execute("SELECT games_id FROM top")
rows = cur.fetchall()
res = []
for i in rows:
res.append(i[0])
return res
def select_from_top_by_pos(conn, pos):
"""
Select game id from top
:param conn: the Connection object
:param pos:
:return: game with id = top_id or blank list
"""
cur = conn.cursor()
cur.execute("SELECT games_id FROM top WHERE id=?", (pos,))
try:
return cur.fetchone()[0][1]
except Exception:
return []
"""##################################################################################################################"""
"""___________________________________________________Cart table_____________________________________________________"""
def add_to_cart(conn, chat_id):
"""
Add new chat_id to cart
:param conn:
:param chat_id:
:return: None
"""
sql = ''' INSERT INTO cart (chat_id, games_id, time_add)
VALUES(?, ?, ?) '''
cur = conn.cursor()
cur.execute(sql, (chat_id, "", int(time.time() * 100)))
def update_cart(conn, data):
"""
Update cart
:param conn:
:param data: chat_id, games_id, time_add
:return: None
"""
sql = ''' UPDATE cart
SET games_id = ?,
time_add = ?
WHERE chat_id = ?'''
cur = conn.cursor()
cur.execute(sql, data)
def delete_cart(conn):
"""
remove table
:return:
"""
sql = "DROP TABLE cart"
cur = conn.cursor()
cur.execute(sql)
def select_all_from_cart(conn):
"""
select all positions in cart for each customer
:param conn:
:return:
"""
cur = conn.cursor()
cur.execute("SELECT * FROM cart")
rows = cur.fetchall()
return rows
def select_cart_for_chat_id(conn, chat_id):
"""
Select all games in cart for customer
:param conn: the Connection object
:param chat_id:
:return: game with id = top_id or blank list
"""
cur = conn.cursor()
cur.execute("SELECT * FROM cart WHERE chat_id=?", (chat_id,))
return cur.fetchone()
"""##################################################################################################################"""
"""__________________________________________________Message table___________________________________________________"""
def add_message(conn, data):
"""
Add new chat_id in Base
:param conn:
:param data:
:return: None
"""
sql = ''' INSERT INTO messages (chat_id, message_id_current)
VALUES(?, ?) '''
cur = conn.cursor()
cur.execute(sql, data)
def update_message(conn, data):
"""
Update the last message_id for chat_id
:param conn:
:param data:
:return: None
"""
sql = ''' UPDATE messages
SET message_id_current = ?
WHERE chat_id = ?'''
cur = conn.cursor()
cur.execute(sql, data)
def update_message_id_last_current(conn, data):
"""
Update the last message_id for chat_id
:param conn:
:param data:
:return: None
"""
sql = ''' UPDATE messages
SET message_id_current = ?,
message_id_last = ?
WHERE chat_id = ?'''
cur = conn.cursor()
cur.execute(sql, data)
def update_message_last_command(conn, chat_id, command):
"""
Update last command and time it was use for chat_id
:param conn:
:param chat_id:
:param command:
:return:
"""
time_msg = int(time.time() * 100)
sql = ''' UPDATE messages
SET command = ?,
time_msg = ?
WHERE chat_id = ?'''
cur = conn.cursor()
data = [command, time_msg, chat_id]
cur.execute(sql, tuple(data))
def update_callback_data(conn, data):
"""
Update last command in messages for double-click protection
:param conn:
:param data:
:return:
"""
sql = ''' UPDATE messages
SET callback = ?
WHERE chat_id = ?'''
cur = conn.cursor()
cur.execute(sql, tuple(data))
def update_callback_now_data(conn, data):
"""
add current command for button back
:param conn:
:param data:
:return:
"""
sql = ''' UPDATE messages
SET callback_now = ?
WHERE chat_id = ?'''
cur = conn.cursor()
cur.execute(sql, tuple(data))
def update_callback_1_data(conn, data):
"""
Implementation of button "back" - pre-pre-last command
:param conn:
:param data:
:return:
"""
sql = ''' UPDATE messages
SET callback_1 = ?
WHERE chat_id = ?'''
cur = conn.cursor()
cur.execute(sql, tuple(data))
def update_callback_2_data(conn, data):
"""
Implementation of button "back" - pre-pre-pre-last command
:param conn:
:param data:
:return:
"""
sql = ''' UPDATE messages
SET callback_2 = ?
WHERE chat_id = ?'''
cur = conn.cursor()
cur.execute(sql, tuple(data))
def update_messages_flag(conn, data):
"""
:param conn:
:param data:
:return:
"""
sql = ''' UPDATE messages
SET flag = ?
WHERE chat_id = ?'''
cur = conn.cursor()
cur.execute(sql, data)
def delete_all_messages(conn):
"""
Delete all messages from table
:param conn: Connection to the SQLite database
:return:
"""
sql = 'DELETE FROM messages'
cur = conn.cursor()
cur.execute(sql)
def delete_messages_table():
"""
remove table
:return:
"""
conn = create_connection(database)
sql = "DROP TABLE messages"
cur = conn.cursor()
cur.execute(sql)
def select_last_command(conn, chat_id):
"""
Select last command and time from messages for chat_id
:param conn:
:param chat_id:
:return: last command and time if exists or blank list
"""
cur = conn.cursor()
cur.execute("SELECT command, time_msg FROM messages Where chat_id=?", (chat_id,))
rows = cur.fetchall()
if len(rows) > 0:
return rows
else:
return -1
def select_message_id_current(conn, chat_id):
"""
Select current message_id for chat_id
:param conn:
:param chat_id:
:return:
"""
cur = conn.cursor()
cur.execute("SELECT message_id_current FROM messages Where chat_id=?", (chat_id,))
rows = cur.fetchall()
if len(rows) > 0:
return rows[0][0]
else:
return 0
def select_message_id_last(conn, chat_id):
"""
Select last message id for chat_id
:param conn:
:param chat_id:
:return:
"""
cur = conn.cursor()
cur.execute("SELECT message_id_last FROM messages Where chat_id=?", (chat_id,))
rows = cur.fetchall()
if len(rows) > 0:
return rows[0][0]
else:
return 0
def select_callback(conn, chat_id):
"""
:param conn:
:param chat_id:
:return:
"""
cur = conn.cursor()
cur.execute("SELECT callback FROM messages Where chat_id=?", (chat_id,))
rows = cur.fetchall()
if len(rows) > 0:
return rows[0][0]
else:
return -1
def select_callback_now(conn, chat_id):
"""
:param conn:
:param chat_id:
:return:
"""
cur = conn.cursor()
cur.execute("SELECT callback_now FROM messages Where chat_id=?", (chat_id,))
rows = cur.fetchall()
if len(rows) > 0:
return rows[0][0]
else:
return -1
def select_callback_1(conn, chat_id):
"""
:param conn:
:param chat_id:
:return:
"""
cur = conn.cursor()
cur.execute("SELECT callback_1 FROM messages Where chat_id=?", (chat_id,))
rows = cur.fetchall()
if len(rows) > 0:
return rows[0][0]
else:
return -1
def select_callback_2(conn, chat_id):
"""
:param conn:
:param chat_id:
:return:
"""
cur = conn.cursor()
cur.execute("SELECT callback_2 FROM messages Where chat_id=?", (chat_id,))
rows = cur.fetchall()
if len(rows) > 0:
return rows[0][0]
else:
return -1
def select_messages_flag(conn, chat_id):
"""
Flag uses for search and chat with developer. If flag == 1 - search, 2 - developer
:param conn:
:param chat_id:
:return:
"""
cur = conn.cursor()
cur.execute("SELECT flag FROM messages Where chat_id=?", (chat_id,))
rows = cur.fetchall()
if len(rows) > 0:
return rows[0][0]
else:
return 0
def select_all_messages(conn):
"""
Select all messages
:param conn:
:return:
"""
cur = conn.cursor()
cur.execute("SELECT * FROM messages")
return cur.fetchall()
"""##################################################################################################################"""
"""_____________________________________________________My ORM_______________________________________________________"""
def show_all_genres():
conn = create_connection(database)
with conn:
res = select_all_genres_from_games(conn)
return res
def show_games_by_genre(genre):
conn = create_connection(database)
with conn:
res = select_games_by_genre(conn, genre)
return res
def show_games_by_id(list_game):
conn = create_connection(database)
res = []
with conn:
for i in list_game:
if '0' <= str(i) <= '99':
res.append(select_game_name_by_id(conn, i))
return res
def show_search_games(list_game):
conn = create_connection(database)
res = []
with conn:
for i in list_game:
res.append("ggame0"+select_game_name_by_id(conn, int(i))[6:])
return res
def show_games_cost_by_id(list_game):
conn = create_connection(database)
res = 0
with conn:
for i in list_game:
if '0' <= i <= '99':
res += (select_game_cost_by_id(conn, i))
return res
def show_game_by_name(name):
conn = create_connection(database)
with conn:
return select_game_by_name(conn, name)
def search_in_games(needle):
conn = create_connection(database)
with conn:
request = select_in_games(conn, needle)
res = []
for i in request:
res.append(str(i[0]))
return res
def show_all_top():
conn = create_connection(database)
with conn:
res = select_all_from_top(conn)
return res
def delete_top_table():
conn = create_connection(database)
with conn:
delete_top(conn)
def delete_games_table():
conn = create_connection(database)
with conn:
delete_games(conn)
def add_new_chat_id(chat_id, message_id):
conn = create_connection(database)
with conn:
add_message(conn, (chat_id, message_id))
def update_message_id_in_chat_id(chat_id, message_id):
data = [str(message_id), str(chat_id)]
conn = create_connection(database)
with conn:
update_message(conn, tuple(data))
def update_message_id_last_and_current(chat_id, message_id_current):
conn = create_connection(database)
with conn:
message_id_last = select_message_id_current(conn, chat_id)
if message_id_current > int(select_message_id_current(conn, chat_id)):
update_message_id_last_current(conn, (message_id_current, message_id_last, chat_id))
def update_callback(chat_id, callback):
conn = create_connection(database)
with conn:
temp = select_callback_now(conn, chat_id)
temp1 = select_callback(conn, chat_id)
temp2 = select_callback_1(conn, chat_id)
if temp != -1:
update_callback_data(conn, (temp, chat_id))
if temp1 != -1:
update_callback_1_data(conn, (temp1, chat_id))
if temp2 != -1:
update_callback_2_data(conn, (temp2, chat_id))
update_callback_now_data(conn, (callback, chat_id))
def remove_callback(chat_id):
conn = create_connection(database)
with conn:
update_callback_now_data(conn, (None, chat_id))
temp2 = select_callback_2(conn, chat_id)
temp1 = select_callback_1(conn, chat_id)
if temp1 == -1:
update_callback_data(conn, ("/start", chat_id))
else:
update_callback_data(conn, (temp1, chat_id))
if temp2 == -1:
update_callback_1_data(conn, (None, chat_id))
else:
update_callback_1_data(conn, (temp2, chat_id))
update_callback_2_data(conn, (None, chat_id))
def show_all_messages():
conn = create_connection(database)
with conn:
res = select_all_messages(conn)
with open("log.txt", 'a') as log:
for i in res:
log.write(str(i))
def show_message_current(chat_id):
conn = create_connection(database)
with conn:
return select_message_id_current(conn, str(chat_id))
def show_message_last(chat_id):
conn = create_connection(database)
with conn:
return select_message_id_last(conn, chat_id)
def show_callback(chat_id):
conn = create_connection(database)
with conn:
res = select_callback(conn, str(chat_id))
if res is None or res == -1 or "Меню:" in res:
return "/start"
else:
return res
def show_last_command_by_chat_id(chat_id):
conn = create_connection(database)
with conn:
return select_last_command(conn, chat_id)
def show_messages_flag(chat_id):
conn = create_connection(database)
with conn:
return select_messages_flag(conn, chat_id)
def update_flag_in_messages(chat_id, flag):
conn = create_connection(database)
with conn:
update_messages_flag(conn, (flag, chat_id))
def delete_messages():
conn = create_connection(database)
with conn:
delete_all_messages(conn)
def double_click_protection(chat_id, command, message_id=None):
now = int(time.time() * 100)
conn = create_connection(database)
i = show_last_command_by_chat_id(chat_id)
with conn:
if len(command) > 6:
command = command[0:6]
if i == -1:
add_message(conn, (chat_id, message_id))
elif i[0][1] is None:
update_message_last_command(conn, chat_id, command)
return 1
elif now - i[0][1] < 100 and command == i[0][0]:
update_message_last_command(conn, chat_id, command)
return 0
update_message_last_command(conn, chat_id, command)
return 1
def new_customer(chat_id):
conn = create_connection(database)
with conn:
add_to_cart(conn, chat_id)
def update_customers_cart(chat_id, game_id):
"""
Обновляемя корзину покупателя. Попадаем сюда либо в случае добавления новых игр либо удаления игр из корзины.
:param chat_id: Чат айди между ботом и пользователем
:param game_id: Айди игры.
:return:
"""
conn = create_connection(database)
temp = select_cart_for_chat_id(conn, chat_id)
time_add = int(time.time() * 100)
if temp is None:
data = [game_id, time_add, chat_id]
time_ = time_add
else:
game_id = temp[1] + "," + game_id
data = [game_id, time_add, chat_id]
time_ = temp[2]
with conn:
if time_add - time_ > 172800:
update_cart(conn, tuple(["", time_add, chat_id]))
update_cart(conn, tuple(data))
def show_cart():
conn = create_connection(database)
with conn:
response = select_all_from_cart(conn)
with open("log.txt", 'a') as log:
for i in response:
log.write(str(i))
def show_cart_for_chat_id(chat_id):
conn = create_connection(database)
with conn:
response = select_cart_for_chat_id(conn, chat_id)
if response is None:
return [0, "", 0]
return response
def delete_game_from_cart(chat_id, text):
conn = create_connection(database)
with conn:
response = select_cart_for_chat_id(conn, chat_id)
if len(text) == 2 and 'A' <= text[1] <= 'Z':
text = text[0]
try:
game_pos_in_text = response[1].rindex(text)
if game_pos_in_text == 0:
temp = response[1][game_pos_in_text + 2:]
else:
temp = response[1][0:game_pos_in_text - 1] + response[1][game_pos_in_text + 2:]
j = 0
for c in temp:
if c == ",":
j += 1
else:
break
if len(temp) == j:
temp = ","
else:
temp = temp[j:]
data = (temp, int(time.time() * 100), response[0])
update_cart(conn, data)
except Exception:
pass
def clear_cart_for_chat_id(chat_id):
conn = create_connection(database)
time_add = int(time.time() * 100)
with conn:
update_cart(conn, tuple([",", time_add, chat_id]))
def delete_cart_table():
conn = create_connection(database)
with conn:
delete_cart(conn)
"""##################################################################################################################"""
def create_tables():
"""
creating (if needed) and filling db
:return: None
"""
sql_create_games_table = """ CREATE TABLE IF NOT EXISTS games (
id integer PRIMARY KEY,
name text NOT NULL,
description text,
genre text NOT NULL,
date text NOT NULL,
photo text NOT NULL,
price integer NOT NULL,
links text,
tempgames1 text,
tempgames2 text,
tempgames3 text
); """
sql_create_message_table = """ CREATE TABLE IF NOT EXISTS messages (
chat_id text PRIMARY KEY NOT NULL,
message_id_current text NOT NULL,
message_id_last text,
command text,
time_msg integer,
callback text,
callback_now text,
callback_1 text,
callback_2 text,
flag integer,
tempmsg1 text,
tempmsg2 text,
tempmsg3 text
); """
sql_create_top_table = """CREATE TABLE IF NOT EXISTS top (
id integer PRIMARY KEY,
games_id integer,
temptop1 text,
FOREIGN KEY (games_id) REFERENCES games (id)
); """
sql_create_cart_table = """ CREATE TABLE IF NOT EXISTS cart (
chat_id integer PRIMARY KEY,
games_id text,
time_add integer,
tempcart1 text,
tempcart2 text,
tempcart3 text
); """
# create a database tables
conn = create_connection(database)
if conn is not None:
create_table(conn, sql_create_games_table)
create_table(conn, sql_create_top_table)
create_table(conn, sql_create_cart_table)