-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
69 lines (57 loc) · 1.66 KB
/
main.py
File metadata and controls
69 lines (57 loc) · 1.66 KB
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
from fastapi import FastAPI
import sqlite3
from fastapi.middleware.cors import CORSMiddleware
app = FastAPI()
origins = [
"http://localhost.tiangolo.com",
"https://localhost.tiangolo.com",
"http://localhost",
"http://localhost:8000"
"http://localhost:8080",
]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.get('/get_todos')
async def get_todos():
# print("Aaryan")
conn = sqlite3.connect("todo_db.db")
cur = conn.execute("select * from todo_table")
todos = cur.fetchall()
todos_json = []
for i in todos:
single_todo = {}
single_todo["id"] = i[0]
single_todo["title"] = i[1]
single_todo["description"] = i[2]
single_todo["status"] = i[3]
todos_json.append(single_todo)
print(todos_json)
print(todos)
return todos_json
@app.post('/create_todo')
async def create_todo(title, description):
conn = sqlite3.connect("todo_db.db")
sql = "INSERT INTO todo_table(title, description) VALUES ('%s', '%s')" % (
title, description)
conn.execute(sql)
conn.commit()
conn.close()
@app.post('/delete_todo')
async def delete_todo(id):
conn = sqlite3.connect("todo_db.db")
sql = "DELETE from todo_table WHERE id=%s" % id
conn.execute(sql)
conn.commit()
conn.close()
# @app.post('/update')
# async def update_todo(title, description, id):
# conn = sqlite3.connect('todo_db.db')
# sql = 'UPDATE todo_table SET title='%s', description='%s' WHERE id={id}' % (title, description)
# conn.execute(sql)
# conn.commit()
# conn.close()