· 4 years ago · Mar 28, 2021, 07:30 AM
1import pymysql
2import cryptography
3
4my_tasks = """
5CREATE TABLE if NOT EXISTS `task` (
6`id` integer not null auto_increment,
7`task` text not null,
8`done` boolean default false,
9primary key(id)
10);
11"""
12db=pymysql.connect(host='localhost', user='michal_dk', password='1234abcd', database='todo_app')
13
14with db.cursor() as c:
15 c.execute("CREATE SCHEMA IF NOT EXISTS `default` DEFAULT CHARACTER SET utf8;")
16 c.execute(my_tasks)
17
18 db.commit()
19db.close()
20
21possible_options=["1", "2", "3", "E", "e"]
22
23selector_switch=""
24while str.lower(selector_switch) != "e":
25 selector_switch = ""
26 while selector_switch not in possible_options:
27 print(" Menu:")
28 print("*"*13)
29 print("Vypis seznam ukolu: stiskni 1")
30 print("Oznac ukol jako splneny: stiskni 2")
31 print("Zadej novy ukol: stiskni 3")
32 print("Ukonci program: stiskni E")
33 print("*"*13)
34 selector_switch=input("Zadej svoji volbu: ")
35
36 if selector_switch=="1":
37 print("Vypis ukolu")
38 print("-"*15)
39 db = pymysql.connect(host='localhost', user='michal_dk', password='1234abcd', database='todo_app')
40
41 with db.cursor() as c:
42 c.execute("SELECT * from task order by id asc;")
43 db.commit()
44 result = c.fetchall()
45 print (result)
46
47 db.close()
48
49 elif selector_switch=="2":
50 print("Oznac splneny ukol")
51 cislo_ukolu=int(input("Zadej cislo splneneho ukolu: "))
52 db = pymysql.connect(host='localhost', user='michal_dk', password='1234abcd', database='todo_app')
53 with db.cursor() as c:
54 c.execute("UPDATE `task` SET done = true WHERE id= (%s);",(cislo_ukolu))
55
56 #c.execute("INSERT INTO `example3` (a,b) VALUES (%s, %s);", (a, b))
57
58 # vlozi zadane hodnoty do DB
59 db.commit()
60 db.close()
61
62 elif selector_switch=="3":
63 print("Zadat novy ukol")
64 ukol=input("Zadej novy ukol: ")
65
66 db = pymysql.connect(host='localhost', user='michal_dk', password='1234abcd', database='todo_app')
67 with db.cursor() as c:
68 c.execute("INSERT INTO `task` (task) VALUES (%s);", (ukol))
69 # vlozi zadane hodnoty do DB
70 db.commit()
71 db.close()
72 else:
73 print("Program bude ukoncen")
74 break;
75
76print("Konec programu")