-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.py
67 lines (59 loc) · 2.29 KB
/
db.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
import sqlite3 as sql
import json
import logging
import traceback
import sys
DATABASE_NAME = 'issuer_database.db'
def test_api_key(client_id, client_secret):
if not isinstance(client_id, str) or not isinstance(client_secret, str) :
return False
try:
con = sql.connect(DATABASE_NAME)
cur = con.cursor()
request = "select * from customers where client_secret='" + client_secret + "' and client_id='" + client_id + "'"
cur.execute(request)
data = cur.fetchone()
con.close()
return data
except sql.Error as er:
logging.error('Database error: %s', ' '.join(er.args))
con.close()
def get_user_kyc(did):
try:
with sql.connect(DATABASE_NAME) as con: #rajouter date kyc dans la table
cur = con.cursor()
cur.execute("select * from kycs where did='" +did+"'")
res=cur.fetchone()
return res
except sql.Error as er:
logging.error('SQLite error: %s', ' '.join(er.args))
finally:
con.close()
def insert_kyc(did,status,id_dossier):
try:
with sql.connect(DATABASE_NAME) as con:
cur = con.cursor()
cur.execute("INSERT INTO kycs (did,status,id) VALUES (?,?,?)",(did,status,id_dossier))
con.commit()
logging.info("kyc successfully added to "+did)
except sql.Error as er:
logging.error(er.args)
exc_type, exc_value, exc_tb = sys.exc_info()
logging.error(traceback.format_exception(exc_type, exc_value, exc_tb))
finally:
con.close()
def update_kyc(did,status,id_dossier):
try:
with sql.connect(DATABASE_NAME) as con:
cur = con.cursor()
cur.execute("update kycs set status='"+status+"',id="+str(id_dossier)+" where did='"+did+"'")
con.commit()
msg = "kyc successfully updated to "+did
logging.info("msg db %s", str(msg))
except sql.Error as er:
logging.error(er.args)
exc_type, exc_value, exc_tb = sys.exc_info()
logging.error(traceback.format_exception(exc_type, exc_value, exc_tb))
finally:
con.close()
logging.info("msg db %s", str(msg))