create core function time_stop

This commit is contained in:
2021-06-04 00:06:58 +02:00
parent d1563a651f
commit 3c2c63e503

View File

@@ -3,7 +3,7 @@
#
# timeTrack.py
# by 4nima
# v.0.4.0
# v.0.5.0
#
#########################
# simple time tracking with database
@@ -351,15 +351,15 @@ class TimeTrack:
userinput = ''
while True:
if userinput == "A" or userinput == "a" or userinput == "1" \
or userinput == "F" or userinput == "f" or userinput == "2" \
or userinput == "L" or userinput == "l" or userinput == "3":
if userinput == "F" or userinput == "f" or userinput == "1" \
or userinput == "L" or userinput == "l" or userinput == "2" \
or userinput == "A" or userinput == "a" or userinput == "3":
break
print('Soll das Event fortgesetzt oder gelöscht werden?')
print('[1/F/f] für fortsetzen')
print('[2/L/l] für löschen')
print('[3/A/a] für abbrechen')
userinput = input('Antwort: ')
userinput = input('Aktion: ')
logging.debug('User input: {}'.format(userinput))
self.clear_screen()
@@ -380,6 +380,69 @@ class TimeTrack:
self.time_stop()
def time_stop(self):
data = self.get_event(USERID=self.USERID)
logging.debug('Event stop progess is started')
if data:
self.clear_screen()
userinput = ''
while True:
if userinput == "B" or userinput == "b" or userinput == "1" \
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")))
print('[1/B/b] für beenden')
print('[2/L/l] für löschen')
print('[3/A/a] für abbrechen')
userinput = input('Aktion: ')
logging.debug('User input: {}'.format(userinput))
self.clear_screen()
if userinput == "B" or userinput == "b" or userinput == "1":
logging.debug('Event is ended')
print('Eingabe beenden mittels doppelter Leerzeile.')
print('Durchgeführte Tätigkeiten:')
userinput = []
while True:
try:
if userinput[-1] == '' and userinput[-2] == '':
break
except IndexError:
pass
userinput.append(input())
del userinput[-1]
del userinput[-1]
action = ''
for i in userinput:
action += i + "\n"
endtime = datetime.datetime.now()
connect = sqlite3.connect(self.DATABASE)
cursor = connect.cursor()
sql = "INSERT INTO time_entries ( starttime, endtime, user_id, activity ) VALUES ( ?, ?, ?, ? )"
try:
cursor.execute(sql, [data[1], endtime, self.USERID, action])
except:
logging.error('Time entry could not be created')
logging.debug(sql)
print('Zeiteintrag konnte nicht gespeichert werden.')
return False
else:
logging.info('Time entry was created successfully')
connect.commit()
self.delete_event(data[0])
connect.close()
elif userinput == "L" or userinput == "l" or userinput == "2":
logging.info('Event should be deleted (eventid: {})'.format(data[0]))
self.delete_event(data[0])
else:
logging.debug('Terminated by the user')
exit()
pass
def get_time(self):