release version 2.2.0a
This commit is contained in:
19
README.md
19
README.md
@@ -2,7 +2,7 @@
|
|||||||
Simple time tracking
|
Simple time tracking
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
- Python 3.9 or higher
|
- Python 3.7 or higher
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
*as of v.2.1.0a*
|
*as of v.2.1.0a*
|
||||||
@@ -10,15 +10,16 @@ Start the script and follow the menu.
|
|||||||
Currently no further usability.
|
Currently no further usability.
|
||||||
|
|
||||||
## Agenda
|
## Agenda
|
||||||
- [ ] Reports
|
- [ ] [Reports](https://git.4nima.net/anima/timetrack/issues/13)
|
||||||
- [x] by day
|
- [x] by day
|
||||||
- [ ] by week
|
- [ ] by week
|
||||||
- [ ] by month
|
- [ ] by month
|
||||||
- [ ] by user
|
- [ ] by user
|
||||||
- [ ] Manual time entries
|
- [ ] [Manual time entries](https://git.4nima.net/anima/timetrack/issues/6)
|
||||||
- [ ] Break in time entries
|
- [ ] [Break in time entries](https://git.4nima.net/anima/timetrack/issues/5)
|
||||||
- [ ] User management
|
- [ ] [Short side tasks](https://git.4nima.net/anima/timetrack/issues/12)
|
||||||
- [ ] Categories
|
- [x] User management
|
||||||
- [ ] Clients
|
- [ ] [Categories](https://git.4nima.net/anima/timetrack/issues/7)
|
||||||
- [ ] References
|
- [ ] [Clients](https://git.4nima.net/anima/timetrack/issues/8)
|
||||||
- [ ] GUI
|
- [ ] [References](https://git.4nima.net/anima/timetrack/issues/9)
|
||||||
|
- [ ] [GUI](https://git.4nima.net/anima/timetrack/issues/10)
|
||||||
|
|||||||
373
timeTrack.py
373
timeTrack.py
@@ -3,7 +3,7 @@
|
|||||||
#
|
#
|
||||||
# timeTrack.py
|
# timeTrack.py
|
||||||
# by 4nima
|
# by 4nima
|
||||||
# v.2.1.0
|
# v.2.2.0a
|
||||||
#
|
#
|
||||||
#########################
|
#########################
|
||||||
# simple time tracking with database
|
# simple time tracking with database
|
||||||
@@ -23,28 +23,32 @@ class TimeTrack:
|
|||||||
self.USERID = 0
|
self.USERID = 0
|
||||||
self.USERNAME = ''
|
self.USERNAME = ''
|
||||||
self.OLDEVENT = 2
|
self.OLDEVENT = 2
|
||||||
|
self.CLIENTS = False
|
||||||
|
self.CATEGORIES = False
|
||||||
|
self.REFERENCES = False
|
||||||
self.LOGFILE = 'timetrack.log'
|
self.LOGFILE = 'timetrack.log'
|
||||||
self.DBCON = sqlite3.connect(self.DATABASE, detect_types=sqlite3.PARSE_DECLTYPES | sqlite3.PARSE_COLNAMES)
|
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
filename=self.LOGFILE,
|
filename=self.LOGFILE,
|
||||||
level=logging.DEBUG,
|
level=logging.DEBUG,
|
||||||
format='%(asctime)s - %(process)d-%(levelname)s: %(message)s',
|
format='%(asctime)s - %(process)d-%(levelname)s: %(message)s',
|
||||||
datefmt='%Y-%m-%d %H:%M:%S'
|
datefmt='%Y-%m-%d %H:%M:%S'
|
||||||
)
|
)
|
||||||
|
if os.name == 'posix':
|
||||||
|
logging.debug('Unix/Linux system detected')
|
||||||
|
self.LINUX = True
|
||||||
|
else:
|
||||||
|
logging.debug('Winwos System detected')
|
||||||
|
|
||||||
self.db_setup()
|
self.db_setup()
|
||||||
self.load_config()
|
self.load_config()
|
||||||
|
|
||||||
def __del__(self):
|
|
||||||
self.DBCON.close()
|
|
||||||
|
|
||||||
## Prepartation
|
## Prepartation
|
||||||
|
#==============
|
||||||
### Check OS and clear screen
|
### Check OS and clear screen
|
||||||
def clear_screen(self):
|
def clear_screen(self):
|
||||||
if os.name == 'posix':
|
if self.LINUX:
|
||||||
logging.debug('Unix/Linux system detected')
|
|
||||||
_ = os.system('clear')
|
_ = os.system('clear')
|
||||||
else:
|
else:
|
||||||
logging.debug('Winwos System detected')
|
|
||||||
_ = os.system('cls')
|
_ = os.system('cls')
|
||||||
|
|
||||||
### Loads or creates a config file
|
### Loads or creates a config file
|
||||||
@@ -60,17 +64,23 @@ class TimeTrack:
|
|||||||
quit()
|
quit()
|
||||||
else:
|
else:
|
||||||
logging.info('Config file was loaded successfully')
|
logging.info('Config file was loaded successfully')
|
||||||
self.USERID = data['user']
|
self.USERID = data['userid']
|
||||||
self.OLDEVENT = data['oldevent']
|
self.OLDEVENT = data['oldevent']
|
||||||
logging.debug('UserID {} was used'.format(data['user']))
|
self.CLIENTS = data['clients']
|
||||||
|
self.CATEGORIES = data['categories']
|
||||||
|
self.REFERENCES = data['references']
|
||||||
|
logging.debug('UserID {} was used'.format(data['userid']))
|
||||||
self.set_user()
|
self.set_user()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
logging.warning('Config file not found')
|
logging.warning('Config file not found')
|
||||||
config = {
|
config = {
|
||||||
'default' : 'interactive',
|
'default' : 'interactive',
|
||||||
'user' : 1,
|
'userid' : 1,
|
||||||
'oldevent' : 2
|
'oldevent' : 2,
|
||||||
|
'clients' : False,
|
||||||
|
'categories' : False,
|
||||||
|
'references' : False
|
||||||
}
|
}
|
||||||
with open(self.CONFIG, "w") as outfile:
|
with open(self.CONFIG, "w") as outfile:
|
||||||
json.dump(config, outfile, indent=4, sort_keys=True)
|
json.dump(config, outfile, indent=4, sort_keys=True)
|
||||||
@@ -92,6 +102,7 @@ class TimeTrack:
|
|||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
starttime TIMESTAMP NOT NULL,
|
starttime TIMESTAMP NOT NULL,
|
||||||
endtime TIMESTAMP NOT NULL,
|
endtime TIMESTAMP NOT NULL,
|
||||||
|
breaktime1 TIMESTAMP,
|
||||||
user_id INTEGER NOT NULL,
|
user_id INTEGER NOT NULL,
|
||||||
activity TEXT,
|
activity TEXT,
|
||||||
reference TEXT,
|
reference TEXT,
|
||||||
@@ -105,6 +116,7 @@ class TimeTrack:
|
|||||||
CREATE TABLE IF NOT EXISTS active_events (
|
CREATE TABLE IF NOT EXISTS active_events (
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
starttime TIMESTAMP NOT NULL,
|
starttime TIMESTAMP NOT NULL,
|
||||||
|
breaktime TIMESTAMP,
|
||||||
user_id INT NOT NULL
|
user_id INT NOT NULL
|
||||||
)
|
)
|
||||||
""")
|
""")
|
||||||
@@ -134,7 +146,7 @@ class TimeTrack:
|
|||||||
|
|
||||||
logging.debug('Create initial database tables')
|
logging.debug('Create initial database tables')
|
||||||
try:
|
try:
|
||||||
with self.DBCON as con:
|
with sqlite3.connect(self.DATABASE, detect_types=sqlite3.PARSE_DECLTYPES | sqlite3.PARSE_COLNAMES) as con:
|
||||||
for SQL in sql:
|
for SQL in sql:
|
||||||
con.execute(SQL)
|
con.execute(SQL)
|
||||||
except sqlite3.Error as err:
|
except sqlite3.Error as err:
|
||||||
@@ -261,6 +273,7 @@ class TimeTrack:
|
|||||||
return timedata
|
return timedata
|
||||||
|
|
||||||
## user handling
|
## user handling
|
||||||
|
#===============
|
||||||
### Creates a user who does not yet exist
|
### Creates a user who does not yet exist
|
||||||
def create_user(self, USER=''):
|
def create_user(self, USER=''):
|
||||||
if USER == '':
|
if USER == '':
|
||||||
@@ -277,8 +290,9 @@ class TimeTrack:
|
|||||||
logging.debug('Accepted username: {}'.format(username))
|
logging.debug('Accepted username: {}'.format(username))
|
||||||
|
|
||||||
sql = "INSERT INTO users ( name ) values ( ? )"
|
sql = "INSERT INTO users ( name ) values ( ? )"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with self.DBCON as con:
|
with sqlite3.connect(self.DATABASE, detect_types=sqlite3.PARSE_DECLTYPES | sqlite3.PARSE_COLNAMES) as con:
|
||||||
con.execute(sql, [username])
|
con.execute(sql, [username])
|
||||||
except sqlite3.Error as err:
|
except sqlite3.Error as err:
|
||||||
logging.error('User could not be saved in database')
|
logging.error('User could not be saved in database')
|
||||||
@@ -303,7 +317,7 @@ class TimeTrack:
|
|||||||
sql = "SELECT * FROM users"
|
sql = "SELECT * FROM users"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with self.DBCON as con:
|
with sqlite3.connect(self.DATABASE, detect_types=sqlite3.PARSE_DECLTYPES | sqlite3.PARSE_COLNAMES) as con:
|
||||||
cur = con.cursor()
|
cur = con.cursor()
|
||||||
if data:
|
if data:
|
||||||
cur.execute(sql, [data])
|
cur.execute(sql, [data])
|
||||||
@@ -335,7 +349,25 @@ class TimeTrack:
|
|||||||
else:
|
else:
|
||||||
self.USERNAME = data[0][1]
|
self.USERNAME = data[0][1]
|
||||||
|
|
||||||
|
def delete_user(self, UID=False):
|
||||||
|
if not UID:
|
||||||
|
logging.error('no userid passed for deletion')
|
||||||
|
else:
|
||||||
|
logging.debug('Userid {} will be delete'.format(UID))
|
||||||
|
sql = "DELETE FROM users WHERE id = ?"
|
||||||
|
|
||||||
|
try:
|
||||||
|
with sqlite3.connect(self.DATABASE, detect_types=sqlite3.PARSE_DECLTYPES | sqlite3.PARSE_COLNAMES) as con:
|
||||||
|
con.execute(sql, [UID])
|
||||||
|
except sqlite3.Error as err:
|
||||||
|
logging.error('User could not be delete from database')
|
||||||
|
logging.debug(sql)
|
||||||
|
logging.error('SQLError: {}'.format(err))
|
||||||
|
else:
|
||||||
|
logging.info('User was delete successfully')
|
||||||
|
|
||||||
## Time handling
|
## Time handling
|
||||||
|
#===============
|
||||||
### Creates an active event if none exists for the user
|
### Creates an active event if none exists for the user
|
||||||
def save_event(self, TIME=datetime.datetime.now()):
|
def save_event(self, TIME=datetime.datetime.now()):
|
||||||
if not self.get_active_event(USERID=self.USERID):
|
if not self.get_active_event(USERID=self.USERID):
|
||||||
@@ -343,7 +375,7 @@ class TimeTrack:
|
|||||||
|
|
||||||
sql = "INSERT INTO active_events ( starttime, user_id ) VALUES ( ?, ? )"
|
sql = "INSERT INTO active_events ( starttime, user_id ) VALUES ( ?, ? )"
|
||||||
try:
|
try:
|
||||||
with self.DBCON as con:
|
with sqlite3.connect(self.DATABASE, detect_types=sqlite3.PARSE_DECLTYPES | sqlite3.PARSE_COLNAMES) as con:
|
||||||
con.execute(sql, [TIME, self.USERID])
|
con.execute(sql, [TIME, self.USERID])
|
||||||
except sqlite3.Error as err:
|
except sqlite3.Error as err:
|
||||||
logging.error('Event could not be created')
|
logging.error('Event could not be created')
|
||||||
@@ -376,7 +408,7 @@ class TimeTrack:
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with self.DBCON as con:
|
with sqlite3.connect(self.DATABASE, detect_types=sqlite3.PARSE_DECLTYPES | sqlite3.PARSE_COLNAMES) as con:
|
||||||
con.execute(sql, [data])
|
con.execute(sql, [data])
|
||||||
except sqlite3.Error as err:
|
except sqlite3.Error as err:
|
||||||
logging.error('Event could not be deleted')
|
logging.error('Event could not be deleted')
|
||||||
@@ -386,7 +418,7 @@ class TimeTrack:
|
|||||||
else:
|
else:
|
||||||
logging.debug('Event was successfully deleted')
|
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):
|
def time_start(self, AUTOFORWARD=True):
|
||||||
self.clear_screen()
|
self.clear_screen()
|
||||||
starttime = datetime.datetime.now()
|
starttime = datetime.datetime.now()
|
||||||
@@ -414,58 +446,45 @@ class TimeTrack:
|
|||||||
else:
|
else:
|
||||||
logging.debug('Event younger than 1 day')
|
logging.debug('Event younger than 1 day')
|
||||||
print('Vergangene Zeit: >{} Stunden'.format(int(elapsed.seconds/3600)))
|
print('Vergangene Zeit: >{} Stunden'.format(int(elapsed.seconds/3600)))
|
||||||
|
|
||||||
|
printtext = [
|
||||||
|
'Wie soll mit dem Event verfahren werden?',
|
||||||
|
'[1] fortsetzen',
|
||||||
|
'[2] löschen',
|
||||||
|
'[0] abbrechen'
|
||||||
|
]
|
||||||
|
userinput = self.userchoise(printtext, 3)
|
||||||
|
self.clear_screen()
|
||||||
|
|
||||||
userinput = 0
|
if userinput == 1:
|
||||||
while not 0 < int(userinput) < 4:
|
|
||||||
print('Soll das Event fortgesetzt oder gelöscht werden?')
|
|
||||||
print('[1] für fortsetzen')
|
|
||||||
print('[2] für löschen')
|
|
||||||
print('[3] für abbrechen')
|
|
||||||
userinput = input('Aktion: ')
|
|
||||||
logging.debug('User input: {}'.format(userinput))
|
|
||||||
try:
|
|
||||||
int(userinput)
|
|
||||||
except ValueError:
|
|
||||||
userinput = 0
|
|
||||||
self.clear_screen()
|
|
||||||
|
|
||||||
if userinput == "1":
|
|
||||||
logging.debug('Event should be continued')
|
logging.debug('Event should be continued')
|
||||||
self.time_stop()
|
self.time_stop()
|
||||||
elif userinput == "2":
|
elif userinput == 2:
|
||||||
logging.info('Event should be deleted (eventid: {})'.format(data[0]))
|
logging.info('Event should be deleted (eventid: {})'.format(data[0]))
|
||||||
self.delete_event(data[0])
|
self.delete_event(data[0])
|
||||||
self.time_start()
|
self.time_start()
|
||||||
else:
|
|
||||||
logging.debug('Terminated by the user')
|
|
||||||
exit()
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
logging.debug('Event continues (eventid{})'.format(data[0]))
|
logging.debug('Event continues (eventid{})'.format(data[0]))
|
||||||
print('Event von {} Uhr geladen'.format(data[1].strftime("%H:%M")))
|
print('Event von {} Uhr geladen'.format(data[1].strftime("%H:%M")))
|
||||||
self.time_stop()
|
self.time_stop()
|
||||||
|
|
||||||
# Stops existing time entries
|
### Stops existing time entries
|
||||||
def time_stop(self):
|
def time_stop(self):
|
||||||
data = self.get_active_event(USERID=self.USERID)
|
data = self.get_active_event(USERID=self.USERID)
|
||||||
logging.debug('Event stop progess is started')
|
logging.debug('Event stop progess is started')
|
||||||
if data:
|
if data:
|
||||||
self.clear_screen()
|
self.clear_screen()
|
||||||
userinput = 0
|
printtext = [
|
||||||
while not 0 < int(userinput) < 4:
|
'Event von {} Uhr beenden?'.format(data[1].strftime("%H:%M")),
|
||||||
print('Event von {} Uhr beenden?'.format(data[1].strftime("%H:%M")))
|
'[1] für beenden',
|
||||||
print('[1] für beenden')
|
'[2] für löschen',
|
||||||
print('[2] für löschen')
|
'[0] für abbrechen'
|
||||||
print('[3] für abbrechen')
|
]
|
||||||
userinput = input('Aktion: ')
|
userinput = self.userchoise(printtext, 3)
|
||||||
logging.debug('User input: {}'.format(userinput))
|
self.clear_screen()
|
||||||
try:
|
|
||||||
int(userinput)
|
|
||||||
except ValueError:
|
|
||||||
userinput = 0
|
|
||||||
self.clear_screen()
|
|
||||||
|
|
||||||
if userinput == "1":
|
if userinput == 1:
|
||||||
logging.debug('Event is ended')
|
logging.debug('Event is ended')
|
||||||
print('Eingabe beenden mittels doppelter Leerzeile.')
|
print('Eingabe beenden mittels doppelter Leerzeile.')
|
||||||
print('Durchgeführte Tätigkeiten:')
|
print('Durchgeführte Tätigkeiten:')
|
||||||
@@ -492,7 +511,7 @@ class TimeTrack:
|
|||||||
|
|
||||||
sql = "INSERT INTO time_entries ( starttime, endtime, user_id, activity ) VALUES ( ?, ?, ?, ? )"
|
sql = "INSERT INTO time_entries ( starttime, endtime, user_id, activity ) VALUES ( ?, ?, ?, ? )"
|
||||||
try:
|
try:
|
||||||
with self.DBCON as con:
|
with sqlite3.connect(self.DATABASE, detect_types=sqlite3.PARSE_DECLTYPES | sqlite3.PARSE_COLNAMES) as con:
|
||||||
con.execute(sql, [data[1], endtime, self.USERID, action])
|
con.execute(sql, [data[1], endtime, self.USERID, action])
|
||||||
except sqlite3.Error as err:
|
except sqlite3.Error as err:
|
||||||
logging.error('Time entry could not be created')
|
logging.error('Time entry could not be created')
|
||||||
@@ -504,60 +523,134 @@ class TimeTrack:
|
|||||||
logging.info('Time entry was created successfully')
|
logging.info('Time entry was created successfully')
|
||||||
|
|
||||||
self.delete_event(data[0])
|
self.delete_event(data[0])
|
||||||
|
self.clear_screen()
|
||||||
self.print_time_entry(STARTTIME=data[1], ENDTIME=endtime, ACTIVITY=action)
|
self.print_time_entry(STARTTIME=data[1], ENDTIME=endtime, ACTIVITY=action)
|
||||||
print('Zeiteintrag wurde gespeichert.')
|
print('Zeiteintrag wurde gespeichert.')
|
||||||
userinput = 0
|
printtext = [
|
||||||
while not 0 < int(userinput) < 3:
|
'Nächsten Zeiteintrag beginnen ?',
|
||||||
print('Nächsten Zeiteintrag beginnen ?')
|
'[1] Ja',
|
||||||
print('[1] Ja')
|
'[0] Nein'
|
||||||
print('[2] Nein')
|
]
|
||||||
userinput = input('Aktion: ')
|
userinput = self.userchoise(printtext)
|
||||||
logging.debug('User input: {}'.format(userinput))
|
self.clear_screen()
|
||||||
try:
|
|
||||||
int(userinput)
|
|
||||||
except ValueError:
|
|
||||||
userinput = 0
|
|
||||||
self.clear_screen()
|
|
||||||
|
|
||||||
if userinput == "1":
|
if userinput == 1:
|
||||||
self.time_start()
|
self.time_start()
|
||||||
else:
|
|
||||||
self.start_interactive_mode()
|
|
||||||
|
|
||||||
elif userinput == "2":
|
elif userinput == 2:
|
||||||
logging.info('Event should be deleted (eventid: {})'.format(data[0]))
|
logging.info('Event should be deleted (eventid: {})'.format(data[0]))
|
||||||
self.delete_event(data[0])
|
self.delete_event(data[0])
|
||||||
else:
|
|
||||||
logging.debug('Terminated by the user')
|
|
||||||
exit()
|
|
||||||
|
|
||||||
def timedela_to_string(self, TIME):
|
## Interactive mode
|
||||||
s = TIME.seconds
|
#==================
|
||||||
hours, remainder = divmod(s, 3600)
|
### Main menu of the interactive menu
|
||||||
minutes, seconds = divmod(remainder, 60)
|
def start_interactive_mode(self):
|
||||||
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=''):
|
|
||||||
self.clear_screen()
|
self.clear_screen()
|
||||||
s = (ENDTIME - STARTTIME).seconds
|
printtext = [
|
||||||
hours, remainder = divmod(s, 3600)
|
'=> Hauptmenü - Angemeldet als {}'.format(self.USERNAME),
|
||||||
minutes, seconds = divmod(remainder, 60)
|
'Was willst du tun?',
|
||||||
|
'[1] Zeiterfassung starten',
|
||||||
print(50*"-")
|
'[2] heutiger Report',
|
||||||
print('Start: {} Uhr'.format(STARTTIME.strftime('%H:%M')))
|
'[3] Reports',
|
||||||
print('Ende: {} Uhr'.format(ENDTIME.strftime('%H:%M')))
|
'[4] Benutzerverwaltung',
|
||||||
print('Dauer: {:02}:{:02}:{:02}'.format(int(hours), int(minutes), int(seconds)))
|
'[0] Programm verlassen'
|
||||||
if not ACTIVITY == '':
|
]
|
||||||
print('Aktivität:')
|
userinput = self.userchoise(printtext, 4)
|
||||||
print(ACTIVITY)
|
|
||||||
print(50*"-")
|
|
||||||
|
|
||||||
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()
|
||||||
|
elif userinput == 3:
|
||||||
|
self.interactive_reports()
|
||||||
|
elif userinput == 4:
|
||||||
|
self.interactive_usermanagment()
|
||||||
|
else:
|
||||||
|
exit()
|
||||||
|
self.start_interactive_mode()
|
||||||
|
|
||||||
|
### Reports menu
|
||||||
|
def interactive_reports(self):
|
||||||
|
self.clear_screen()
|
||||||
|
printtext = [
|
||||||
|
'==> Reports für {}'.format(self.USERNAME),
|
||||||
|
'Welcher Report soll angezeigt werden?',
|
||||||
|
'[1] Tages Report von [Datum]',
|
||||||
|
'[0] abbrechen'
|
||||||
|
]
|
||||||
|
userinput = self.userchoise(printtext, 2)
|
||||||
|
|
||||||
|
if userinput == 1:
|
||||||
|
valid = False
|
||||||
|
while not valid:
|
||||||
|
self.clear_screen()
|
||||||
|
print('Report für welches Datum soll angezeigt werden?')
|
||||||
|
print('[0] für abbruch')
|
||||||
|
userdate = input("Datum: [yyyy-mm-dd]:")
|
||||||
|
if userdate == 0:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
date = datetime.datetime.strptime(userdate, "%Y-%m-%d")
|
||||||
|
valid = True
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
self.report_by_day(date.date())
|
||||||
|
|
||||||
|
### Usermanagment menu
|
||||||
|
def interactive_usermanagment(self):
|
||||||
|
self.clear_screen()
|
||||||
|
printtext = [
|
||||||
|
'==> Benutzerverwaltung - Angemeldet als {}'.format(self.USERNAME),
|
||||||
|
'Was willst du tun?',
|
||||||
|
'[1] Benutzer anlegen',
|
||||||
|
'[2] Benutzer wechseln',
|
||||||
|
'[3] Benutzer löschen',
|
||||||
|
'[0] abbrechen'
|
||||||
|
]
|
||||||
|
userinput = self.userchoise(printtext, 4)
|
||||||
|
|
||||||
|
if userinput == 1:
|
||||||
|
self.create_user()
|
||||||
|
elif userinput == 2:
|
||||||
|
users = self.get_users()
|
||||||
|
printtext = ['Wähle deinen User:']
|
||||||
|
count = 1
|
||||||
|
for user in users:
|
||||||
|
printtext.append('[{}] {}'.format(count, user[1]))
|
||||||
|
count += 1
|
||||||
|
|
||||||
|
printtext.append('[0] abbrechen')
|
||||||
|
userid = self.userchoise(printtext, count)
|
||||||
|
self.USERID = users[userid - 1][0]
|
||||||
|
self.set_user()
|
||||||
|
elif userinput == 3:
|
||||||
|
users = self.get_users()
|
||||||
|
printtext = ['Welcher User soll gelöscht werden?:']
|
||||||
|
count = 1
|
||||||
|
for user in users:
|
||||||
|
printtext.append('[{}] {}'.format(count, user[1]))
|
||||||
|
count += 1
|
||||||
|
|
||||||
|
printtext.append('[0] abbrechen')
|
||||||
|
userid = self.userchoise(printtext, count)
|
||||||
|
self.delete_user(users[userid - 1][0])
|
||||||
|
|
||||||
|
## Reports
|
||||||
|
#=========
|
||||||
|
### One day report, optionally with time entries
|
||||||
|
def report_by_day(self, DATE=datetime.date.today(), USER='', DETAIL=''):
|
||||||
if not USER:
|
if not USER:
|
||||||
USER = self.USERID
|
USER = self.USERID
|
||||||
timedata = self.get_time_entry(DAY=DATE, USERID=USER)
|
timedata = self.get_time_entry(DAY=DATE, USERID=USER)
|
||||||
|
if timedata == 0:
|
||||||
|
print("Es wurden keine Zeiteinträge für den angegeben Tag gefunden")
|
||||||
|
logging.debug('No time entries for date: '.format(DATE))
|
||||||
|
input()
|
||||||
|
return 1
|
||||||
|
|
||||||
STARTTIMES = []
|
STARTTIMES = []
|
||||||
ENDTIMES = []
|
ENDTIMES = []
|
||||||
@@ -577,50 +670,68 @@ class TimeTrack:
|
|||||||
ENTRIECOUNT = len(timedata)
|
ENTRIECOUNT = len(timedata)
|
||||||
|
|
||||||
self.clear_screen()
|
self.clear_screen()
|
||||||
print('{:40} {}'.format("Beginn des ersten Zeiteintrags:", FIRSTSTARTTIME.strftime('%d.%m.%Y %H:%M')))
|
text = "{:40} {}"
|
||||||
print('{:40} {}'.format("Ende des letzen Zeiteintrags:", LASTENDTIME.strftime('%d.%m.%Y %H:%M')))
|
print(text.format("Beginn des ersten Zeiteintrags:", FIRSTSTARTTIME.strftime('%d.%m.%Y %H:%M')))
|
||||||
print('{:40} {}'.format("Maximal erfassbare Zeit:", self.timedela_to_string(TRACKEDTIMESPAN)))
|
print(text.format("Ende des letzen Zeiteintrags:", LASTENDTIME.strftime('%d.%m.%Y %H:%M')))
|
||||||
print('{:40} {}'.format("Nicht erfasste Zeit:", self.timedela_to_string(NONTRACKEDTIME)))
|
print(text.format("Maximal erfassbare Zeit:", self.timedela_to_string(TRACKEDTIMESPAN)))
|
||||||
print('{:40} {}'.format("Erfasste Zeit:", self.timedela_to_string(TRACKEDTIME)))
|
print(text.format("Nicht erfasste Zeit:", self.timedela_to_string(NONTRACKEDTIME)))
|
||||||
print('{:40} {}'.format("Zeiteinträge:", ENTRIECOUNT))
|
print(text.format("Erfasste Zeit:", self.timedela_to_string(TRACKEDTIME)))
|
||||||
|
print(text.format("Zeiteinträge:", ENTRIECOUNT))
|
||||||
|
|
||||||
def start_interactive_mode(self):
|
printtext = [
|
||||||
self.clear_screen()
|
'Zeiteinträge anzeigen?',
|
||||||
userinput = 0
|
'[1] Ja',
|
||||||
while not 0 < int(userinput) < 4:
|
'[0] Nein'
|
||||||
print('Was willst du tun?')
|
]
|
||||||
print('[1] für Zeiterfassung starten')
|
userinput = self.userchoise(printtext)
|
||||||
print('[2] für heutiger Report')
|
if userinput == 1:
|
||||||
print('[3] für Report für Tag x')
|
for entry in timedata:
|
||||||
print('[9] für Programm verlassen')
|
self.print_time_entry(entry[1], entry[2], entry[4])
|
||||||
|
|
||||||
|
## 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: ')
|
userinput = input('Aktion: ')
|
||||||
logging.debug('User input: {}'.format(userinput))
|
logging.debug('User input: {}'.format(userinput))
|
||||||
try:
|
try:
|
||||||
int(userinput)
|
int(userinput)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
userinput = 0
|
userinput = -1
|
||||||
else:
|
else:
|
||||||
if int(userinput) == 9:
|
self.clear_screen()
|
||||||
logging.debug('Terminated by the user')
|
return int(userinput)
|
||||||
exit()
|
|
||||||
self.clear_screen()
|
|
||||||
|
|
||||||
if userinput == "1":
|
### Conversion to string of Timedelta typ
|
||||||
logging.debug('Start TimeTrack')
|
def timedela_to_string(self, TIME):
|
||||||
self.time_start()
|
s = TIME.seconds
|
||||||
elif userinput == "2":
|
hours, remainder = divmod(s, 3600)
|
||||||
logging.info('Print todays report')
|
minutes, seconds = divmod(remainder, 60)
|
||||||
self.report_by_day()
|
output = '{:02}:{:02}:{:02}'.format(int(hours), int(minutes), int(seconds))
|
||||||
input()
|
return output
|
||||||
self.start_interactive_mode()
|
|
||||||
elif userinput == "3":
|
|
||||||
print('commig soon ...')
|
|
||||||
input()
|
|
||||||
self.start_interactive_mode()
|
|
||||||
|
|
||||||
print(userinput)
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
test = TimeTrack()
|
test = TimeTrack()
|
||||||
test.start_interactive_mode()
|
test.start_interactive_mode()
|
||||||
test.DBCON.close()
|
|
||||||
Reference in New Issue
Block a user