build core time function
This commit is contained in:
54
timeTrack.py
54
timeTrack.py
@@ -10,6 +10,7 @@
|
||||
#########################
|
||||
|
||||
import datetime
|
||||
import time
|
||||
import sqlite3
|
||||
import json
|
||||
import os
|
||||
@@ -44,8 +45,8 @@ class TimeTrack:
|
||||
sql.append("""
|
||||
CREATE TABLE IF NOT EXISTS time_entries (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
starttime DATETIME NOT NULL,
|
||||
endtime DATETIME NOT NULL,
|
||||
starttime TIMESTAMP NOT NULL,
|
||||
endtime TIMESTAMP NOT NULL,
|
||||
user_id INTEGER NOT NULL,
|
||||
activity TEXT,
|
||||
catrgory_id INTEGER,
|
||||
@@ -57,7 +58,7 @@ class TimeTrack:
|
||||
sql.append("""
|
||||
CREATE TABLE IF NOT EXISTS active_events (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
starttime DATETIME NOT NULL,
|
||||
starttime TIMESTAMP NOT NULL,
|
||||
user_id INT NOT NULL
|
||||
)
|
||||
""")
|
||||
@@ -217,4 +218,51 @@ class TimeTrack:
|
||||
except IndexError:
|
||||
logging.error('User ID was not found')
|
||||
|
||||
def time_start(self):
|
||||
starttime = datetime.datetime.now()
|
||||
time.sleep(10)
|
||||
endtime = datetime.datetime.now()
|
||||
print('Start: {}'.format(starttime))
|
||||
print('Ende: {}'.format(endtime))
|
||||
print('Diff: {}'.format(endtime - starttime))
|
||||
sql = """
|
||||
INSERT INTO time_entries
|
||||
( starttime, endtime, user_id )
|
||||
VALUES ( ?, ?, ?)
|
||||
"""
|
||||
connect = sqlite3.connect(self.DATABASE)
|
||||
cursor = connect.cursor()
|
||||
cursor.execute(sql, (starttime, endtime, self.USERID))
|
||||
logging.debug(sql)
|
||||
|
||||
connect.commit()
|
||||
connect.close()
|
||||
|
||||
def time_end(self):
|
||||
pass
|
||||
|
||||
|
||||
def get_time(self):
|
||||
connect = sqlite3.connect(self.DATABASE, detect_types=sqlite3.PARSE_DECLTYPES | sqlite3.PARSE_COLNAMES)
|
||||
cursor = connect.cursor()
|
||||
|
||||
connect.commit()
|
||||
|
||||
sql = """SELECT * FROM time_entries"""
|
||||
cursor.execute(sql)
|
||||
|
||||
row = cursor.fetchall()
|
||||
for i in row:
|
||||
print(i)
|
||||
print('Start: {}'.format(i[1]))
|
||||
print('End: {}'.format(i[2]))
|
||||
print('Diff: {}'.format(i[2] - i[1]))
|
||||
endtime = i[2]
|
||||
|
||||
connect.close()
|
||||
|
||||
|
||||
|
||||
test = TimeTrack()
|
||||
test.time_start()
|
||||
test.get_time()
|
||||
Reference in New Issue
Block a user