-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsqltrack.py
41 lines (32 loc) · 961 Bytes
/
sqltrack.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
import sqlite3
from datetime import datetime, timedelta
def create_database():
conn = sqlite3.connect("move.db")
c = conn.cursor()
try:
c.execute("create table move (date text, position real)")
conn.commit()
conn.close()
add_move(datetime.today(), 0.0)
except sqlite3.OperationalError:
print("Already exists")
def add_move(date,position):
conn = sqlite3.connect("move.db")
c = conn.cursor()
c.execute("insert into move(date,position) values(?,?)", [date, position])
conn.commit()
conn.close()
def get_last_position():
conn = sqlite3.connect("move.db")
c = conn.cursor()
c.execute("select max(position) from move")
ret = c.fetchone()
conn.close()
return ret[0]
def get_all_position():
conn = sqlite3.connect("move.db")
c = conn.cursor()
c.execute("select * from move order by position")
for row in c:
print(row)
conn.close()