-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.py
40 lines (33 loc) · 1003 Bytes
/
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
import peewee as pw
import os
from time import sleep
vehicle_id="101"
db=pw.SqliteDatabase("admin")
db.connect()
db.execute_sql("""create table admin_cards(
id varchar(100) primary key NOT NULL,
purpose varchar(40) NOT NULL
);""")
atr=os.popen("node card2.js").read().split('\n')
while atr[0]!="card inserted":
atr=os.popen("node card2.js").read().split('\n')
continue
print(atr)
print(" added as addition card")
db.execute_sql("""insert into admin_cards values('%s','add')"""%atr[1])
comp=False
while not comp:
atr=os.popen("node card2.js").read().split('\n')
while atr[0]!="card inserted":
atr=os.popen("node card2.js").read().split('\n')
continue
print(atr)
try:
db.execute_sql("""insert into admin_cards values('%s','delete')"""%atr[1])
print(atr)
print(" added as deletion card")
comp=True
except:
print("Already registered card")
sleep(2)
db.close()