finish time_stop function
This commit is contained in:
59
timeTrack.py
59
timeTrack.py
@@ -209,11 +209,8 @@ class TimeTrack:
|
||||
connect.commit()
|
||||
|
||||
data = cursor.fetchall()
|
||||
output = []
|
||||
for row in data:
|
||||
output.append(row)
|
||||
connect.close()
|
||||
return output
|
||||
return data
|
||||
|
||||
### Defines a user for the session
|
||||
def set_user(self):
|
||||
@@ -258,7 +255,7 @@ class TimeTrack:
|
||||
### Deletes an active event based on a user or event ID
|
||||
def delete_event(self, ENTRYID='', USERID=''):
|
||||
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 = ?"
|
||||
data = ENTRYID
|
||||
elif not USERID == '':
|
||||
@@ -326,9 +323,11 @@ class TimeTrack:
|
||||
def time_start(self, AUTOFORWARD=True):
|
||||
self.clear_screen()
|
||||
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):
|
||||
print('Neues Event gestartet um {}'.format(starttime.strftime("%H:%M")))
|
||||
if AUTOFORWARD:
|
||||
self.time_stop()
|
||||
else:
|
||||
data = self.get_event(USERID=self.USERID)
|
||||
print('Es existiert bereits ein aktives Event.')
|
||||
@@ -387,7 +386,7 @@ class TimeTrack:
|
||||
userinput = ''
|
||||
while True:
|
||||
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":
|
||||
break
|
||||
print('Event von {} Uhr beenden?'.format(data[1].strftime("%H:%M")))
|
||||
@@ -411,13 +410,17 @@ class TimeTrack:
|
||||
pass
|
||||
userinput.append(input())
|
||||
|
||||
logging.debug('User input: {}'.format(userinput))
|
||||
del userinput[-1]
|
||||
del userinput[-1]
|
||||
action = ''
|
||||
for i in userinput:
|
||||
action += i + "\n"
|
||||
if not action == '':
|
||||
action += "\n"
|
||||
action += i
|
||||
|
||||
endtime = datetime.datetime.now()
|
||||
logging.debug('Event end process start at {}'.format(endtime))
|
||||
connect = sqlite3.connect(self.DATABASE)
|
||||
cursor = connect.cursor()
|
||||
sql = "INSERT INTO time_entries ( starttime, endtime, user_id, activity ) VALUES ( ?, ?, ?, ? )"
|
||||
@@ -433,6 +436,25 @@ class TimeTrack:
|
||||
logging.info('Time entry was created successfully')
|
||||
connect.commit()
|
||||
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()
|
||||
|
||||
@@ -443,14 +465,25 @@ class TimeTrack:
|
||||
logging.debug('Terminated by the user')
|
||||
exit()
|
||||
|
||||
pass
|
||||
|
||||
def get_time(self):
|
||||
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.delete_event(USERID=1)
|
||||
#test.save_event()
|
||||
#test.get_event()
|
||||
test.time_start()
|
||||
Reference in New Issue
Block a user