-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper.py
82 lines (71 loc) · 2.22 KB
/
helper.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
import pymysql
def connect():
return pymysql.connect(
host='localhost',
user='root',
password='',
db='todoflask',
charset='utf8'
)
NOTSTARTED = 'Not Started'
INPROGRESS = 'In Progress'
COMPLETED = 'Completed'
def add_to_list(item, stat):
try:
conn = connect()
# Once a connection has been established, we use the cursor
# object to execute queries
with conn.cursor() as c:
# Keep the initial status as Not Started
c.execute('INSERT INTO items(item, status) VALUES (%s, %s)', (item, stat))
# We commit to save the change
conn.commit()
conn.close()
except Exception as e:
print('Adding list error: ', e)
def get_all_items():
try:
conn = connect()
list=[]
with conn.cursor() as c:
c.execute('SELECT item, status FROM items')
list = c.fetchall()
conn.close()
return list
except Exception as e:
print('Showing all error: ', e)
return None
def get_status(item):
try:
conn = connect()
with conn.cursor() as c:
c.execute("SELECT status FROM items WHERE item=%s" ,(item))
status = c.fetchone()[0]
conn.close()
return status
except Exception as e:
print('Get Status error: ', e)
return None
def update_status(item, status):
try:
conn = connect()
with conn.cursor() as c:
c.execute('UPDATE items SET status=%s WHERE item=%s', (status, item))
conn.commit()
conn.close()
except Exception as e:
print('Updating error: ', e)
return None
def delete_item(item):
try:
conn = connect()
with conn.cursor() as c:
c.execute('DELETE FROM items WHERE item=%s', (item))
conn.commit()
conn.close()
except Exception as e:
print('Deleting error: ', e)
return None
"""if __name__=='__main__':
articulos=get_all_items()
print(articulos)"""