Creation update de la bdd et renvoie des coordonnees
This commit is contained in:
parent
4a375a3217
commit
b195b5d17e
1 changed files with 24 additions and 2 deletions
|
@ -2,7 +2,8 @@
|
|||
|
||||
from flask import Flask
|
||||
import pandas as pd
|
||||
import pysqlite3 as sql
|
||||
import sqlite3 as sql
|
||||
import json
|
||||
|
||||
|
||||
def create_app():
|
||||
|
@ -11,11 +12,32 @@ def create_app():
|
|||
data=pd.read_csv("/Datasets/database/questions.csv",delimiter=",")
|
||||
data.to_sql('questions',con,if_exists='replace',index=False)
|
||||
|
||||
@app.route('/question/<int:id>',methods=['GET'])
|
||||
@app.route('/get_question/<int:id>/',methods=['GET'])
|
||||
def get_question(id=1):
|
||||
with sql.connect("/Datasets/database/database.db") as con:
|
||||
cur = con.cursor()
|
||||
row = cur.execute("select * from questions where id=\'"+str(id)+"\';")
|
||||
return(row.fetchone()[2])
|
||||
|
||||
@app.route('/create/<string:token>/')
|
||||
def create(token='TEST'):
|
||||
with sql.connect("/Datasets/database/database.db") as con:
|
||||
data=pd.read_csv("/Datasets/database/"+token+".csv",delimiter=";")
|
||||
data.to_sql(token,con,if_exists='replace',index=False)
|
||||
return '1'
|
||||
|
||||
@app.route('/update/<string:token>/<string:attr>/<int:value>/')
|
||||
def update(token,attr,value):
|
||||
with sql.connect("/Datasets/database/database.db") as con:
|
||||
cur = con.cursor()
|
||||
sql_update= "update " + token + " set excluded = 1 where "+attr+"="+str(value)+";"
|
||||
cur.execute(sql_update)
|
||||
cur.execute("select x,y from "+token+" where "+attr+"=\'"+str(value)+"\';")
|
||||
rows = cur.fetchall()
|
||||
dico = dict()
|
||||
dico["img"]=rows
|
||||
cur = con.cursor()
|
||||
cur.execute("SELECT COUNT(*) FROM "+token+" where excluded = 0")
|
||||
dico["Nb"]=cur.fetchone()[0]
|
||||
return(json.dumps(dico))
|
||||
return app
|
||||
|
|
Loading…
Reference in a new issue