finish time_stop function
This commit is contained in:
59
timeTrack.py
59
timeTrack.py
@@ -209,11 +209,8 @@ class TimeTrack:
|
|||||||
connect.commit()
|
connect.commit()
|
||||||
|
|
||||||
data = cursor.fetchall()
|
data = cursor.fetchall()
|
||||||
output = []
|
|
||||||
for row in data:
|
|
||||||
output.append(row)
|
|
||||||
connect.close()
|
connect.close()
|
||||||
return output
|
return data
|
||||||
|
|
||||||
### Defines a user for the session
|
### Defines a user for the session
|
||||||
def set_user(self):
|
def set_user(self):
|
||||||
@@ -258,7 +255,7 @@ class TimeTrack:
|
|||||||
### Deletes an active event based on a user or event ID
|
### Deletes an active event based on a user or event ID
|
||||||
def delete_event(self, ENTRYID='', USERID=''):
|
def delete_event(self, ENTRYID='', USERID=''):
|
||||||
if not ENTRYID == '':
|
if not ENTRYID == '':
|
||||||
logging.info('Deletes event based on eventid: {}'.format(USERID))
|
logging.info('Deletes event based on eventid: {}'.format(ENTRYID))
|
||||||
sql = "DELETE FROM active_events WHERE id = ?"
|
sql = "DELETE FROM active_events WHERE id = ?"
|
||||||
data = ENTRYID
|
data = ENTRYID
|
||||||
elif not USERID == '':
|
elif not USERID == '':
|
||||||
@@ -326,9 +323,11 @@ class TimeTrack:
|
|||||||
def time_start(self, AUTOFORWARD=True):
|
def time_start(self, AUTOFORWARD=True):
|
||||||
self.clear_screen()
|
self.clear_screen()
|
||||||
starttime = datetime.datetime.now()
|
starttime = datetime.datetime.now()
|
||||||
logging.info('New Event process started at {}'.format(starttime))
|
logging.debug('New Event process started at {}'.format(starttime))
|
||||||
if self.save_event(starttime):
|
if self.save_event(starttime):
|
||||||
print('Neues Event gestartet um {}'.format(starttime.strftime("%H:%M")))
|
print('Neues Event gestartet um {}'.format(starttime.strftime("%H:%M")))
|
||||||
|
if AUTOFORWARD:
|
||||||
|
self.time_stop()
|
||||||
else:
|
else:
|
||||||
data = self.get_event(USERID=self.USERID)
|
data = self.get_event(USERID=self.USERID)
|
||||||
print('Es existiert bereits ein aktives Event.')
|
print('Es existiert bereits ein aktives Event.')
|
||||||
@@ -387,7 +386,7 @@ class TimeTrack:
|
|||||||
userinput = ''
|
userinput = ''
|
||||||
while True:
|
while True:
|
||||||
if userinput == "B" or userinput == "b" or userinput == "1" \
|
if userinput == "B" or userinput == "b" or userinput == "1" \
|
||||||
or userinput == "l" or userinput == "l" or userinput == "2" \
|
or userinput == "L" or userinput == "l" or userinput == "2" \
|
||||||
or userinput == "A" or userinput == "a" or userinput == "3":
|
or userinput == "A" or userinput == "a" or userinput == "3":
|
||||||
break
|
break
|
||||||
print('Event von {} Uhr beenden?'.format(data[1].strftime("%H:%M")))
|
print('Event von {} Uhr beenden?'.format(data[1].strftime("%H:%M")))
|
||||||
@@ -411,13 +410,17 @@ class TimeTrack:
|
|||||||
pass
|
pass
|
||||||
userinput.append(input())
|
userinput.append(input())
|
||||||
|
|
||||||
|
logging.debug('User input: {}'.format(userinput))
|
||||||
del userinput[-1]
|
del userinput[-1]
|
||||||
del userinput[-1]
|
del userinput[-1]
|
||||||
action = ''
|
action = ''
|
||||||
for i in userinput:
|
for i in userinput:
|
||||||
action += i + "\n"
|
if not action == '':
|
||||||
|
action += "\n"
|
||||||
|
action += i
|
||||||
|
|
||||||
endtime = datetime.datetime.now()
|
endtime = datetime.datetime.now()
|
||||||
|
logging.debug('Event end process start at {}'.format(endtime))
|
||||||
connect = sqlite3.connect(self.DATABASE)
|
connect = sqlite3.connect(self.DATABASE)
|
||||||
cursor = connect.cursor()
|
cursor = connect.cursor()
|
||||||
sql = "INSERT INTO time_entries ( starttime, endtime, user_id, activity ) VALUES ( ?, ?, ?, ? )"
|
sql = "INSERT INTO time_entries ( starttime, endtime, user_id, activity ) VALUES ( ?, ?, ?, ? )"
|
||||||
@@ -433,6 +436,25 @@ class TimeTrack:
|
|||||||
logging.info('Time entry was created successfully')
|
logging.info('Time entry was created successfully')
|
||||||
connect.commit()
|
connect.commit()
|
||||||
self.delete_event(data[0])
|
self.delete_event(data[0])
|
||||||
|
self.print_time_entry(STARTTIME=data[1], ENDTIME=endtime, ACTIVITY=action)
|
||||||
|
print('Zeiteintrag wurde gespeichert.')
|
||||||
|
while True:
|
||||||
|
if userinput == "J" or userinput == "j" or userinput == "1" \
|
||||||
|
or userinput == "N" or userinput == "n" or userinput == "2":
|
||||||
|
break
|
||||||
|
print('Nächsten Zeiteintrag begrinnen ?')
|
||||||
|
print('[1/J/j] Ja')
|
||||||
|
print('[2/N/n] Nein')
|
||||||
|
userinput = input('Aktion: ')
|
||||||
|
logging.debug('User input: {}'.format(userinput))
|
||||||
|
self.clear_screen()
|
||||||
|
|
||||||
|
if userinput == "J" or userinput == "j" or userinput == "1":
|
||||||
|
self.time_start()
|
||||||
|
else:
|
||||||
|
logging.debug('Terminated by the user')
|
||||||
|
exit()
|
||||||
|
|
||||||
|
|
||||||
connect.close()
|
connect.close()
|
||||||
|
|
||||||
@@ -443,14 +465,25 @@ class TimeTrack:
|
|||||||
logging.debug('Terminated by the user')
|
logging.debug('Terminated by the user')
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
pass
|
|
||||||
|
|
||||||
def get_time(self):
|
def get_time(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def print_time_entry(self, STARTTIME='', ENDTIME='', ACTIVITY=''):
|
||||||
|
s = (ENDTIME - STARTTIME).seconds
|
||||||
|
hours, remainder = divmod(s, 3600)
|
||||||
|
minutes, seconds = divmod(remainder, 60)
|
||||||
|
|
||||||
|
print(50*"-")
|
||||||
|
print('Start: {} Uhr'.format(STARTTIME.strftime('%H:%M')))
|
||||||
|
print('Ende: {} Uhr'.format(ENDTIME.strftime('%H:%M')))
|
||||||
|
print('Dauer: {:02}:{:02}:{:02}'.format(int(hours), int(minutes), int(seconds)))
|
||||||
|
if not ACTIVITY == '':
|
||||||
|
print('Aktivität:')
|
||||||
|
print(ACTIVITY)
|
||||||
|
print(50*"-")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
test = TimeTrack()
|
test = TimeTrack()
|
||||||
#test.delete_event(USERID=1)
|
|
||||||
#test.save_event()
|
|
||||||
#test.get_event()
|
|
||||||
test.time_start()
|
test.time_start()
|
||||||
Reference in New Issue
Block a user