From 29dc5c0e5898cb78050bdc2e154e1084e816d31e Mon Sep 17 00:00:00 2001
From: anima
Date: Thu, 3 Jun 2021 15:32:22 +0200
Subject: [PATCH] build core time function
---
timeTrack.py | 56 ++++++++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 52 insertions(+), 4 deletions(-)
diff --git a/timeTrack.py b/timeTrack.py
index 39e25a8..282fcf1 100644
--- a/timeTrack.py
+++ b/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')
-test = TimeTrack()
\ No newline at end of file
+ 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()
\ No newline at end of file