From c081f519ddb2b4aea80737f1a1fd5eed71d703ca Mon Sep 17 00:00:00 2001
From: anima
Date: Tue, 8 Jun 2021 23:48:44 +0200
Subject: [PATCH] add function userchoise and print time entries by daly report
---
timeTrack.py | 139 ++++++++++++++++++++++++++++++++-------------------
1 file changed, 87 insertions(+), 52 deletions(-)
diff --git a/timeTrack.py b/timeTrack.py
index 8b1425d..0a51567 100644
--- a/timeTrack.py
+++ b/timeTrack.py
@@ -38,6 +38,7 @@ class TimeTrack:
self.DBCON.close()
## Prepartation
+ #==============
### Check OS and clear screen
def clear_screen(self):
if os.name == 'posix':
@@ -261,6 +262,7 @@ class TimeTrack:
return timedata
## user handling
+ #===============
### Creates a user who does not yet exist
def create_user(self, USER=''):
if USER == '':
@@ -336,6 +338,7 @@ class TimeTrack:
self.USERNAME = data[0][1]
## Time handling
+ #===============
### Creates an active event if none exists for the user
def save_event(self, TIME=datetime.datetime.now()):
if not self.get_active_event(USERID=self.USERID):
@@ -386,7 +389,7 @@ class TimeTrack:
else:
logging.debug('Event was successfully deleted')
- # Checks for existing time entries and creates a new one if none is available.
+ ### Checks for existing time entries and creates a new one if none is available.
def time_start(self, AUTOFORWARD=True):
self.clear_screen()
starttime = datetime.datetime.now()
@@ -445,7 +448,7 @@ class TimeTrack:
print('Event von {} Uhr geladen'.format(data[1].strftime("%H:%M")))
self.time_stop()
- # Stops existing time entries
+ ### Stops existing time entries
def time_stop(self):
data = self.get_active_event(USERID=self.USERID)
logging.debug('Event stop progess is started')
@@ -504,6 +507,7 @@ class TimeTrack:
logging.info('Time entry was created successfully')
self.delete_event(data[0])
+ self.clear_screen()
self.print_time_entry(STARTTIME=data[1], ENDTIME=endtime, ACTIVITY=action)
print('Zeiteintrag wurde gespeichert.')
userinput = 0
@@ -531,30 +535,41 @@ class TimeTrack:
logging.debug('Terminated by the user')
exit()
- def timedela_to_string(self, TIME):
- s = TIME.seconds
- hours, remainder = divmod(s, 3600)
- minutes, seconds = divmod(remainder, 60)
- output = '{:02}:{:02}:{:02}'.format(int(hours), int(minutes), int(seconds))
- return output
-
- # Shows a time entry
- def print_time_entry(self, STARTTIME='', ENDTIME='', ACTIVITY=''):
+ ## Interactive mode
+ #==================
+ ### Main menu of the interactive menu
+ def start_interactive_mode(self):
self.clear_screen()
- 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*"-")
+ printtext = [
+ 'Was willst du tun?',
+ '[1] Zeiterfassung starten',
+ '[2] heutiger Report',
+ '[3] Report für Tag x',
+ '[0] Programm verlassen'
+ ]
+ userinput = self.userchoise(printtext, 4)
- def report_by_day(self, DATE=datetime.date.today(), USER=''):
+ if userinput == 1:
+ logging.debug('Start TimeTrack')
+ self.time_start()
+ elif userinput == 2:
+ logging.info('Print todays report')
+ self.report_by_day(DETAIL=True)
+ input()
+ self.start_interactive_mode()
+ elif userinput == 3:
+ print('commig soon ...')
+ input()
+ self.start_interactive_mode()
+ elif userinput == 4:
+ print('commig soon ...')
+ input()
+ self.start_interactive_mode()
+
+ ## Reports
+ #=========
+ ### One day report, optionally with time entries
+ def report_by_day(self, DATE=datetime.date.today(), USER='', DETAIL=''):
if not USER:
USER = self.USERID
timedata = self.get_time_entry(DAY=DATE, USERID=USER)
@@ -584,41 +599,61 @@ class TimeTrack:
print('{:40} {}'.format("Erfasste Zeit:", self.timedela_to_string(TRACKEDTIME)))
print('{:40} {}'.format("Zeiteinträge:", ENTRIECOUNT))
- def start_interactive_mode(self):
- self.clear_screen()
- userinput = 0
- while not 0 < int(userinput) < 4:
- print('Was willst du tun?')
- print('[1] für Zeiterfassung starten')
- print('[2] für heutiger Report')
- print('[3] für Report für Tag x')
- print('[9] für Programm verlassen')
+ printtext = [
+ 'Zeiteinträge anzeigen?',
+ '[1] Ja',
+ '[0] Nein'
+ ]
+ userinput = self.userchoise(printtext)
+ if userinput == 1:
+ for entry in timedata:
+ self.print_time_entry(entry[1], entry[2], entry[4])
+ else:
+ self.start_interactive_mode()
+
+ ## Outputs
+ #=========
+ ### Shows a time entry
+ 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*"-")
+
+ ## Miscellaneous
+ #===============
+ ### User selection
+ def userchoise(self, TEXT='', MAX=2):
+ userinput = -1
+ while not -1 < int(userinput) < MAX:
+ for text in TEXT:
+ print(text)
userinput = input('Aktion: ')
logging.debug('User input: {}'.format(userinput))
try:
int(userinput)
except ValueError:
- userinput = 0
+ userinput = -1
else:
- if int(userinput) == 9:
- logging.debug('Terminated by the user')
- exit()
- self.clear_screen()
+ self.clear_screen()
+ return int(userinput)
- if userinput == "1":
- logging.debug('Start TimeTrack')
- self.time_start()
- elif userinput == "2":
- logging.info('Print todays report')
- self.report_by_day()
- input()
- self.start_interactive_mode()
- elif userinput == "3":
- print('commig soon ...')
- input()
- self.start_interactive_mode()
-
- print(userinput)
+ ### Conversion to string of Timedelta typ
+ def timedela_to_string(self, TIME):
+ s = TIME.seconds
+ hours, remainder = divmod(s, 3600)
+ minutes, seconds = divmod(remainder, 60)
+ output = '{:02}:{:02}:{:02}'.format(int(hours), int(minutes), int(seconds))
+ return output
+
if __name__ == "__main__":
test = TimeTrack()