Compare commits
10 Commits
aa2c08838e
...
v.2.1.0a
| Author | SHA1 | Date | |
|---|---|---|---|
| 35ee16479a | |||
| 3da9195697 | |||
| e4d533b249 | |||
| b774ec6e1e | |||
| fc3f350e96 | |||
| 4801df4b5f | |||
| 21ce7ab426 | |||
| 33c99066a1 | |||
| 3c6c4f731c | |||
| 4a5aa37174 |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -1,4 +0,0 @@
|
|||||||
*.log
|
|
||||||
*.conf
|
|
||||||
*.db
|
|
||||||
.vscode
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
24
README.md
Normal file
24
README.md
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
# Timetrack
|
||||||
|
Simple time tracking
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
- Python 3.9 or higher
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
*as of v.2.1.0a*
|
||||||
|
Start the script and follow the menu.
|
||||||
|
Currently no further usability.
|
||||||
|
|
||||||
|
## Agenda
|
||||||
|
- [ ] Reports
|
||||||
|
- [x] by day
|
||||||
|
- [ ] by week
|
||||||
|
- [ ] by month
|
||||||
|
- [ ] by user
|
||||||
|
- [ ] Manual time entries
|
||||||
|
- [ ] Break in time entries
|
||||||
|
- [ ] User management
|
||||||
|
- [ ] Categories
|
||||||
|
- [ ] Clients
|
||||||
|
- [ ] References
|
||||||
|
- [ ] GUI
|
||||||
373
timeTrack.py
373
timeTrack.py
@@ -3,7 +3,7 @@
|
|||||||
#
|
#
|
||||||
# timeTrack.py
|
# timeTrack.py
|
||||||
# by 4nima
|
# by 4nima
|
||||||
# v.2.2.0a
|
# v.2.1.0
|
||||||
#
|
#
|
||||||
#########################
|
#########################
|
||||||
# simple time tracking with database
|
# simple time tracking with database
|
||||||
@@ -23,32 +23,28 @@ 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 self.LINUX:
|
if os.name == 'posix':
|
||||||
|
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
|
||||||
@@ -64,23 +60,17 @@ class TimeTrack:
|
|||||||
quit()
|
quit()
|
||||||
else:
|
else:
|
||||||
logging.info('Config file was loaded successfully')
|
logging.info('Config file was loaded successfully')
|
||||||
self.USERID = data['userid']
|
self.USERID = data['user']
|
||||||
self.OLDEVENT = data['oldevent']
|
self.OLDEVENT = data['oldevent']
|
||||||
self.CLIENTS = data['clients']
|
logging.debug('UserID {} was used'.format(data['user']))
|
||||||
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',
|
||||||
'userid' : 1,
|
'user' : 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)
|
||||||
@@ -102,7 +92,6 @@ 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,
|
||||||
@@ -116,7 +105,6 @@ 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
|
||||||
)
|
)
|
||||||
""")
|
""")
|
||||||
@@ -146,7 +134,7 @@ class TimeTrack:
|
|||||||
|
|
||||||
logging.debug('Create initial database tables')
|
logging.debug('Create initial database tables')
|
||||||
try:
|
try:
|
||||||
with sqlite3.connect(self.DATABASE, detect_types=sqlite3.PARSE_DECLTYPES | sqlite3.PARSE_COLNAMES) as con:
|
with self.DBCON 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:
|
||||||
@@ -273,7 +261,6 @@ 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 == '':
|
||||||
@@ -290,9 +277,8 @@ 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 sqlite3.connect(self.DATABASE, detect_types=sqlite3.PARSE_DECLTYPES | sqlite3.PARSE_COLNAMES) as con:
|
with self.DBCON 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')
|
||||||
@@ -317,7 +303,7 @@ class TimeTrack:
|
|||||||
sql = "SELECT * FROM users"
|
sql = "SELECT * FROM users"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with sqlite3.connect(self.DATABASE, detect_types=sqlite3.PARSE_DECLTYPES | sqlite3.PARSE_COLNAMES) as con:
|
with self.DBCON as con:
|
||||||
cur = con.cursor()
|
cur = con.cursor()
|
||||||
if data:
|
if data:
|
||||||
cur.execute(sql, [data])
|
cur.execute(sql, [data])
|
||||||
@@ -349,25 +335,7 @@ 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):
|
||||||
@@ -375,7 +343,7 @@ class TimeTrack:
|
|||||||
|
|
||||||
sql = "INSERT INTO active_events ( starttime, user_id ) VALUES ( ?, ? )"
|
sql = "INSERT INTO active_events ( starttime, user_id ) VALUES ( ?, ? )"
|
||||||
try:
|
try:
|
||||||
with sqlite3.connect(self.DATABASE, detect_types=sqlite3.PARSE_DECLTYPES | sqlite3.PARSE_COLNAMES) as con:
|
with self.DBCON 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')
|
||||||
@@ -408,7 +376,7 @@ class TimeTrack:
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with sqlite3.connect(self.DATABASE, detect_types=sqlite3.PARSE_DECLTYPES | sqlite3.PARSE_COLNAMES) as con:
|
with self.DBCON 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')
|
||||||
@@ -418,7 +386,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()
|
||||||
@@ -446,45 +414,58 @@ 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()
|
|
||||||
|
|
||||||
if userinput == 1:
|
userinput = 0
|
||||||
|
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()
|
||||||
printtext = [
|
userinput = 0
|
||||||
'Event von {} Uhr beenden?'.format(data[1].strftime("%H:%M")),
|
while not 0 < int(userinput) < 4:
|
||||||
'[1] für beenden',
|
print('Event von {} Uhr beenden?'.format(data[1].strftime("%H:%M")))
|
||||||
'[2] für löschen',
|
print('[1] für beenden')
|
||||||
'[0] für abbrechen'
|
print('[2] für löschen')
|
||||||
]
|
print('[3] für abbrechen')
|
||||||
userinput = self.userchoise(printtext, 3)
|
userinput = input('Aktion: ')
|
||||||
self.clear_screen()
|
logging.debug('User input: {}'.format(userinput))
|
||||||
|
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:')
|
||||||
@@ -511,7 +492,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 sqlite3.connect(self.DATABASE, detect_types=sqlite3.PARSE_DECLTYPES | sqlite3.PARSE_COLNAMES) as con:
|
with self.DBCON 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')
|
||||||
@@ -523,134 +504,60 @@ 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.')
|
||||||
printtext = [
|
userinput = 0
|
||||||
'Nächsten Zeiteintrag beginnen ?',
|
while not 0 < int(userinput) < 3:
|
||||||
'[1] Ja',
|
print('Nächsten Zeiteintrag beginnen ?')
|
||||||
'[0] Nein'
|
print('[1] Ja')
|
||||||
]
|
print('[2] Nein')
|
||||||
userinput = self.userchoise(printtext)
|
userinput = input('Aktion: ')
|
||||||
self.clear_screen()
|
logging.debug('User input: {}'.format(userinput))
|
||||||
|
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()
|
||||||
|
|
||||||
## Interactive mode
|
def timedela_to_string(self, TIME):
|
||||||
#==================
|
s = TIME.seconds
|
||||||
### Main menu of the interactive menu
|
hours, remainder = divmod(s, 3600)
|
||||||
def start_interactive_mode(self):
|
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=''):
|
||||||
self.clear_screen()
|
self.clear_screen()
|
||||||
printtext = [
|
s = (ENDTIME - STARTTIME).seconds
|
||||||
'=> Hauptmenü - Angemeldet als {}'.format(self.USERNAME),
|
hours, remainder = divmod(s, 3600)
|
||||||
'Was willst du tun?',
|
minutes, seconds = divmod(remainder, 60)
|
||||||
'[1] Zeiterfassung starten',
|
|
||||||
'[2] heutiger Report',
|
print(50*"-")
|
||||||
'[3] Reports',
|
print('Start: {} Uhr'.format(STARTTIME.strftime('%H:%M')))
|
||||||
'[4] Benutzerverwaltung',
|
print('Ende: {} Uhr'.format(ENDTIME.strftime('%H:%M')))
|
||||||
'[0] Programm verlassen'
|
print('Dauer: {:02}:{:02}:{:02}'.format(int(hours), int(minutes), int(seconds)))
|
||||||
]
|
if not ACTIVITY == '':
|
||||||
userinput = self.userchoise(printtext, 4)
|
print('Aktivität:')
|
||||||
|
print(ACTIVITY)
|
||||||
|
print(50*"-")
|
||||||
|
|
||||||
if userinput == 1:
|
def report_by_day(self, DATE=datetime.date.today(), USER=''):
|
||||||
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 = []
|
||||||
@@ -670,68 +577,50 @@ class TimeTrack:
|
|||||||
ENTRIECOUNT = len(timedata)
|
ENTRIECOUNT = len(timedata)
|
||||||
|
|
||||||
self.clear_screen()
|
self.clear_screen()
|
||||||
text = "{:40} {}"
|
print('{:40} {}'.format("Beginn des ersten Zeiteintrags:", FIRSTSTARTTIME.strftime('%d.%m.%Y %H:%M')))
|
||||||
print(text.format("Beginn des ersten Zeiteintrags:", FIRSTSTARTTIME.strftime('%d.%m.%Y %H:%M')))
|
print('{:40} {}'.format("Ende des letzen Zeiteintrags:", LASTENDTIME.strftime('%d.%m.%Y %H:%M')))
|
||||||
print(text.format("Ende des letzen Zeiteintrags:", LASTENDTIME.strftime('%d.%m.%Y %H:%M')))
|
print('{:40} {}'.format("Maximal erfassbare Zeit:", self.timedela_to_string(TRACKEDTIMESPAN)))
|
||||||
print(text.format("Maximal erfassbare Zeit:", self.timedela_to_string(TRACKEDTIMESPAN)))
|
print('{:40} {}'.format("Nicht erfasste Zeit:", self.timedela_to_string(NONTRACKEDTIME)))
|
||||||
print(text.format("Nicht erfasste Zeit:", self.timedela_to_string(NONTRACKEDTIME)))
|
print('{:40} {}'.format("Erfasste Zeit:", self.timedela_to_string(TRACKEDTIME)))
|
||||||
print(text.format("Erfasste Zeit:", self.timedela_to_string(TRACKEDTIME)))
|
print('{:40} {}'.format("Zeiteinträge:", ENTRIECOUNT))
|
||||||
print(text.format("Zeiteinträge:", ENTRIECOUNT))
|
|
||||||
|
|
||||||
printtext = [
|
def start_interactive_mode(self):
|
||||||
'Zeiteinträge anzeigen?',
|
self.clear_screen()
|
||||||
'[1] Ja',
|
userinput = 0
|
||||||
'[0] Nein'
|
while not 0 < int(userinput) < 4:
|
||||||
]
|
print('Was willst du tun?')
|
||||||
userinput = self.userchoise(printtext)
|
print('[1] für Zeiterfassung starten')
|
||||||
if userinput == 1:
|
print('[2] für heutiger Report')
|
||||||
for entry in timedata:
|
print('[3] für Report für Tag x')
|
||||||
self.print_time_entry(entry[1], entry[2], entry[4])
|
print('[9] für Programm verlassen')
|
||||||
|
|
||||||
## 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 = -1
|
userinput = 0
|
||||||
else:
|
else:
|
||||||
self.clear_screen()
|
if int(userinput) == 9:
|
||||||
return int(userinput)
|
logging.debug('Terminated by the user')
|
||||||
|
exit()
|
||||||
|
self.clear_screen()
|
||||||
|
|
||||||
### Conversion to string of Timedelta typ
|
if userinput == "1":
|
||||||
def timedela_to_string(self, TIME):
|
logging.debug('Start TimeTrack')
|
||||||
s = TIME.seconds
|
self.time_start()
|
||||||
hours, remainder = divmod(s, 3600)
|
elif userinput == "2":
|
||||||
minutes, seconds = divmod(remainder, 60)
|
logging.info('Print todays report')
|
||||||
output = '{:02}:{:02}:{:02}'.format(int(hours), int(minutes), int(seconds))
|
self.report_by_day()
|
||||||
return output
|
input()
|
||||||
|
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()
|
||||||
540
timeTrack.sh
540
timeTrack.sh
@@ -1,540 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
#==========
|
|
||||||
#
|
|
||||||
# timeTrack.sh
|
|
||||||
# by 4nima
|
|
||||||
# v.1.5.0
|
|
||||||
#
|
|
||||||
#==========
|
|
||||||
# Einfaches Erfassen von Zeiten mit einer SQLDB (SQLite, kein Server)
|
|
||||||
#==========
|
|
||||||
|
|
||||||
|
|
||||||
# Variablen Definieren
|
|
||||||
#=====================
|
|
||||||
# Pfad zur Datenbank (Vollständiger Pfad benutzen!)
|
|
||||||
DBDIR="/root/time/work/.timeTrack.db"
|
|
||||||
DB="timeTrack"
|
|
||||||
|
|
||||||
## Verfügbare Kategorien (0 = Default)
|
|
||||||
### ACHTUNG: in der DB werden die IDs gespeichert, verändern der Rheinfolge verfälscht Reports
|
|
||||||
# Alternativ neben Kategorien noch Tags oder Projekte anbieten
|
|
||||||
declare -a categories
|
|
||||||
categories[0]="Junk"
|
|
||||||
categories+=("Kunden")
|
|
||||||
categories+=("Internes")
|
|
||||||
categories+=("Meetings")
|
|
||||||
categories+=("Schulung")
|
|
||||||
categories+=("Pause")
|
|
||||||
categories+=("Sonstiges")
|
|
||||||
categories+=("Privates")
|
|
||||||
|
|
||||||
# Funktionen
|
|
||||||
#===========
|
|
||||||
## DB
|
|
||||||
### Erstellt eine Datenbank Datei
|
|
||||||
function createDB {
|
|
||||||
sqlite3 $DBDIR "
|
|
||||||
CREATE TABLE IF NOT EXISTS $DB (
|
|
||||||
id INTEGER PRIMARY KEY,
|
|
||||||
date INTEGER,
|
|
||||||
day INTEGER,
|
|
||||||
kw INTEGER,
|
|
||||||
task TEXT,
|
|
||||||
category INTEGER,
|
|
||||||
worktime INTEGER
|
|
||||||
);
|
|
||||||
"
|
|
||||||
}
|
|
||||||
|
|
||||||
### Fügt einen Task in die DB ein
|
|
||||||
function insertTask {
|
|
||||||
sqlite3 $DBDIR "
|
|
||||||
INSERT INTO $DB (
|
|
||||||
date,
|
|
||||||
day,
|
|
||||||
kw,
|
|
||||||
task,
|
|
||||||
category,
|
|
||||||
worktime
|
|
||||||
) VALUES (
|
|
||||||
'$(date +%s)',
|
|
||||||
'$(date +%u)',
|
|
||||||
'$(date +%V)',
|
|
||||||
'$1',
|
|
||||||
'$2',
|
|
||||||
'$3'
|
|
||||||
);
|
|
||||||
"
|
|
||||||
}
|
|
||||||
|
|
||||||
### Eintrag aus der Datenbank löschen
|
|
||||||
function eraseTask {
|
|
||||||
echo "<================================================>"
|
|
||||||
sqlite3 $DBDIR "
|
|
||||||
DELETE
|
|
||||||
FROM $DB
|
|
||||||
WHERE id = $DBID
|
|
||||||
"
|
|
||||||
echo "Task wurde gelöscht"
|
|
||||||
echo "<================================================>"
|
|
||||||
}
|
|
||||||
|
|
||||||
### Suche
|
|
||||||
#### Anhand der ID
|
|
||||||
function searchById {
|
|
||||||
echo "<================================================>"
|
|
||||||
sqlite3 $DBDIR -column -header "
|
|
||||||
SELECT *
|
|
||||||
FROM $DB
|
|
||||||
WHERE id = $DBID
|
|
||||||
"
|
|
||||||
echo "<================================================>"
|
|
||||||
}
|
|
||||||
|
|
||||||
#### Anhand eines Strings (in Tasks)
|
|
||||||
function searchByString {
|
|
||||||
echo "<================================================>"
|
|
||||||
sqlite3 $DBDIR -column -header "
|
|
||||||
SELECT *
|
|
||||||
FROM $DB
|
|
||||||
WHERE task LIKE '%$SEARCH%'
|
|
||||||
"
|
|
||||||
echo "<================================================>"
|
|
||||||
}
|
|
||||||
|
|
||||||
### Updates
|
|
||||||
#### Datum
|
|
||||||
function updateDate {
|
|
||||||
echo "<================================================>"
|
|
||||||
sqlite3 $DBDIR "
|
|
||||||
UPDATE $DB
|
|
||||||
SET date = '$UPDATEVALUE'
|
|
||||||
WHERE id = $DBID
|
|
||||||
"
|
|
||||||
echo "Datum geupdatet"
|
|
||||||
echo "<================================================>"
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateTask {
|
|
||||||
echo "<================================================>"
|
|
||||||
sqlite3 $DBDIR "
|
|
||||||
UPDATE $DB
|
|
||||||
SET task = '$UPDATEVALUE'
|
|
||||||
WHERE id = $DBID
|
|
||||||
"
|
|
||||||
echo "Task geupdatet"
|
|
||||||
echo "<================================================>"
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateCategory {
|
|
||||||
echo "<================================================>"
|
|
||||||
sqlite3 $DBDIR "
|
|
||||||
UPDATE $DB
|
|
||||||
SET category = '$UPDATEVALUE'
|
|
||||||
WHERE id = $DBID
|
|
||||||
"
|
|
||||||
echo "Kategorie geupdatet"
|
|
||||||
echo "<================================================>"
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateWorktime {
|
|
||||||
echo "<================================================>"
|
|
||||||
sqlite3 $DBDIR "
|
|
||||||
UPDATE $DB
|
|
||||||
SET worktime = '$UPDATEVALUE'
|
|
||||||
WHERE id = $DBID
|
|
||||||
"
|
|
||||||
echo " Arbeitszeit geupdatet"
|
|
||||||
echo "<================================================>"
|
|
||||||
}
|
|
||||||
|
|
||||||
### Reports
|
|
||||||
#### Auslesen aller Heutigen Tasks
|
|
||||||
function dailyReport {
|
|
||||||
echo "<================================================>"
|
|
||||||
day=$(convertDay $(date +%u))
|
|
||||||
echo "Daly Report vom $day - KW $(date +%V)"
|
|
||||||
sqlite3 $DBDIR -column -header "
|
|
||||||
SELECT
|
|
||||||
count(id) AS 'Tasks',
|
|
||||||
time(sum(worktime), 'unixepoch') AS 'Arbeitszeit'
|
|
||||||
FROM $DB
|
|
||||||
WHERE kw = '$(date +%V)'
|
|
||||||
AND day = '$(date +%u)'
|
|
||||||
"
|
|
||||||
echo
|
|
||||||
}
|
|
||||||
|
|
||||||
function weeklyReport {
|
|
||||||
echo "<================================================>"
|
|
||||||
echo "Weekly Report vom KW $(date +%V)"
|
|
||||||
sqlite3 $DBDIR -column -header "
|
|
||||||
SELECT
|
|
||||||
count(id) AS 'Tasks',
|
|
||||||
time(sum(worktime), 'unixepoch') AS 'Arbeitszeit'
|
|
||||||
FROM $DB
|
|
||||||
WHERE kw = '$(date +%V)'
|
|
||||||
"
|
|
||||||
echo
|
|
||||||
}
|
|
||||||
|
|
||||||
function dailyCategoryReport {
|
|
||||||
day=$(convertDay $(date +%u))
|
|
||||||
for i in ${!categories[@]}; do
|
|
||||||
echo "<================================================>"
|
|
||||||
echo "Report für Kategorie: ${categories[i]}"
|
|
||||||
echo "Für $day in KW: $(date +%V)"
|
|
||||||
sqlite3 $DBDIR -column -header "
|
|
||||||
SELECT
|
|
||||||
count(id) AS 'Tasks',
|
|
||||||
time(sum(worktime), 'unixepoch') AS 'Arbeitszeit'
|
|
||||||
FROM $DB
|
|
||||||
WHERE kw = '$(date +%V)'
|
|
||||||
AND day = '$(date +%u)'
|
|
||||||
AND category = '$i'
|
|
||||||
"
|
|
||||||
echo
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
function weeklyCategoryReport {
|
|
||||||
week=$(convertDay $(date +%u))
|
|
||||||
for i in ${!categories[@]}; do
|
|
||||||
echo "<================================================>"
|
|
||||||
echo "Report für Kategorie: ${categories[i]}"
|
|
||||||
echo "In KW: $(date +%V)"
|
|
||||||
sqlite3 $DBDIR -column -header "
|
|
||||||
SELECT
|
|
||||||
count(id) AS 'Tasks',
|
|
||||||
time(sum(worktime), 'unixepoch') AS 'Arbeitszeit'
|
|
||||||
FROM $DB
|
|
||||||
WHERE kw = '$(date +%V)'
|
|
||||||
AND category = '$i'
|
|
||||||
"
|
|
||||||
echo
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
## Abläufe
|
|
||||||
### Prüft ob SQLite3 installiert ist und erstellt eine Datenbank wenn nicht schon vorhanden
|
|
||||||
function checkRequirements {
|
|
||||||
dpkg -l sqlite3
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
echo "Bitte sqlite3 installieren!"
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ ! -d $DIR ];then
|
|
||||||
mkdir -r $DIR
|
|
||||||
fi
|
|
||||||
createDB
|
|
||||||
}
|
|
||||||
|
|
||||||
### Start des Trackings und Tätigkeits Abfrage
|
|
||||||
function startTracking {
|
|
||||||
starttime=$(date +%s)
|
|
||||||
echo "<================================================>"
|
|
||||||
echo "Time Tracking gestartet um: $(date +%H:%M)"
|
|
||||||
IFS= read -a doingwords -p "Tätigkeit? `echo $'\n> '`"
|
|
||||||
doing=${doingwords[0]}
|
|
||||||
}
|
|
||||||
|
|
||||||
### Beendet das Tacking und Kategorie Abfrage
|
|
||||||
function endTracking {
|
|
||||||
for i in ${!categories[@]}; do
|
|
||||||
echo "$i. ${categories[i]}"
|
|
||||||
done
|
|
||||||
IFS= read -p "Kategorie? `echo $'\n> '`" category
|
|
||||||
endtime=$(date +%s)
|
|
||||||
worktime=$(($endtime - $starttime))
|
|
||||||
}
|
|
||||||
|
|
||||||
### Erstellt eine Zusammenfassung zu dem eben Bearbeiteten Task
|
|
||||||
#### Verbesserung: Möglichkeit auch Tasks aus der DB erneut auszugeben
|
|
||||||
function printTask {
|
|
||||||
echo "<================================================>"
|
|
||||||
echo "Time Tracking beendet um $(date +%H:%M) - $outputtime"
|
|
||||||
echo "<================================================>"
|
|
||||||
echo "Du hast $outputtime in ${categories[$category]} investiert"
|
|
||||||
echo "<================================================>"
|
|
||||||
echo "Task: $doing"
|
|
||||||
echo "<================================================>"
|
|
||||||
}
|
|
||||||
|
|
||||||
### Aufruf bei -D(atenbank)
|
|
||||||
function showDB {
|
|
||||||
sqlite3 $DBDIR -column -header "SELECT * from $DB"
|
|
||||||
}
|
|
||||||
|
|
||||||
### Aufruf bei -c(onfig) [/path/to/config.file]
|
|
||||||
function config {
|
|
||||||
if [ -f $OPTARG ];then
|
|
||||||
config=$OPTARG
|
|
||||||
echo $config
|
|
||||||
# Datei einlesen; Prüfung was angepasst wurde (DB / DB file / Kategorien); validieren; weiter oder exit.
|
|
||||||
else
|
|
||||||
echo "Dieses Konfigfile existiert nicht"
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
### Aufruf bei -e(rase) [DB ID]
|
|
||||||
function erase {
|
|
||||||
if [[ $OPTARG =~ ^[0-9]+$ ]]; then
|
|
||||||
DBID=$OPTARG
|
|
||||||
searchById
|
|
||||||
IFS= read -p "Diesen Eintrag löschen?(y/n) `echo $'\n> '`" DELIT
|
|
||||||
if [ $DELIT == "Y" ] || [ $DELIT == "y" ]; then
|
|
||||||
eraseTask
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo "Gib die ID des zu löschenden Tasks ein"
|
|
||||||
echo "Mit '-s' kannst du eine Suche starten"
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
### Aufruf bei -h(elp)
|
|
||||||
function printHelp {
|
|
||||||
echo '
|
|
||||||
Benutzung: ./timeTrack.sh [option [argument]]
|
|
||||||
|
|
||||||
Ohne Option wird das Skript für eine Zeitmessung ausgeführt und dann beendet.
|
|
||||||
|
|
||||||
Optionen:
|
|
||||||
-D # Listet die Tabelle der Datenbank auf
|
|
||||||
-c [arg] # Konfigurationsdatei
|
|
||||||
-e [DB ID] # Eintrag aus Tabelle löschen (Siehe -s)
|
|
||||||
-h # Zeigt diese Hilfe
|
|
||||||
-H [option] # Zeigt Detail Hilfe zu der Option
|
|
||||||
-i # Startet eine Aufgaben speicherung mit eigenen Zeiteingaben
|
|
||||||
-l # Startet das Skript im Loop (abbrechen mit Strg + C)
|
|
||||||
-r [type] # Zeigt Reports für [day / week / month / category / ...]
|
|
||||||
-s [string] # Sucht in der Datenbank nach [string] (nur im Aufgaben Feld)
|
|
||||||
-u [DB ID] # Update für bereits vorhandene Einträge in der Datenbank (Siehe -s)
|
|
||||||
'
|
|
||||||
}
|
|
||||||
|
|
||||||
### Aufrug bei -H(elp) [option]
|
|
||||||
function helpTo {
|
|
||||||
case $1 in
|
|
||||||
c)
|
|
||||||
echo '
|
|
||||||
Benutzung: ./timeTrack.sh -c /path/to/my.conf
|
|
||||||
|
|
||||||
Mit der Option -c kann ein eine Konigurationsdatei angegeben werden.
|
|
||||||
In der Konfigurationsdatei können individuelle Parameter übergeben werden:
|
|
||||||
Pfad zur Datenbankdatei:
|
|
||||||
DBDIR="/path/to/file.db" # Vollständigen Pfad angeben
|
|
||||||
|
|
||||||
In der Datenbankdatei die Tabelle festlegen:
|
|
||||||
DB="myTable" # Keine Sonder- oder Leerzeichen
|
|
||||||
|
|
||||||
Eigene Kategorien:
|
|
||||||
categories[0]="Default") # Standard Kategorie
|
|
||||||
categories+=("newCategory") # Hinzufügen einer Kategorie (wiederholbar)
|
|
||||||
'
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
exit
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
### Aufruf bei -i(nsert)
|
|
||||||
function insert {
|
|
||||||
IFS= read -p "Tätigkeit? `echo $'\n> '`" TASK
|
|
||||||
IFS= read -p "Dauer? `echo $'\n> '`" WORKTIME
|
|
||||||
IFS= read -p "Endzeit? `echo $'\n> '`" ENDDATE
|
|
||||||
IFS= read -p "Kategorie? `echo $'\n> '`" CATEGORY
|
|
||||||
}
|
|
||||||
|
|
||||||
### Aufruf bei -r(eport) [Ansicht...]
|
|
||||||
function report {
|
|
||||||
REPORT=$OPTARG
|
|
||||||
clear
|
|
||||||
case $REPORT in
|
|
||||||
day|daily)
|
|
||||||
dailyReport
|
|
||||||
dailyCategoryReport
|
|
||||||
;;
|
|
||||||
week|weekly)
|
|
||||||
weeklyReport
|
|
||||||
weeklyCategoryReport
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
dailyReport
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
### Standard Aufruf
|
|
||||||
function default {
|
|
||||||
checkRequirements
|
|
||||||
clear
|
|
||||||
startTracking
|
|
||||||
endTracking
|
|
||||||
calcWorktime $worktime
|
|
||||||
insertTask "$doing" "$category" "$worktime"
|
|
||||||
clear
|
|
||||||
printTask
|
|
||||||
}
|
|
||||||
|
|
||||||
### Aufruf bei -s(earch) [Suchstring]
|
|
||||||
function search {
|
|
||||||
# Optionen ob damit was gemacht werden soll (Update / Löschen)
|
|
||||||
SEARCH=$OPTARG
|
|
||||||
searchByString
|
|
||||||
}
|
|
||||||
|
|
||||||
### Aufruf bei -u(pdate) [DB ID]
|
|
||||||
function update {
|
|
||||||
# Prüfung ob angaben stimmen, weitere eingaben ändern
|
|
||||||
DBID=$OPTARG
|
|
||||||
searchById
|
|
||||||
echo "
|
|
||||||
1. Datum
|
|
||||||
2. Task
|
|
||||||
3. Kategorie
|
|
||||||
4. Arbeitszeit
|
|
||||||
"
|
|
||||||
IFS= read -p "Was soll geupdatet werden? `echo $'\n> '`" UPDATETYPE
|
|
||||||
IFS= read -p "Was soll eingetragen werden? `echo $'\n> '`" UPDATEVALUE
|
|
||||||
case $UPDATETYPE in
|
|
||||||
1|Datum)
|
|
||||||
updateDate
|
|
||||||
;;
|
|
||||||
2|Task)
|
|
||||||
updateTask
|
|
||||||
;;
|
|
||||||
3|Kategorie)
|
|
||||||
updateCategory
|
|
||||||
;;
|
|
||||||
4|Arbeitszeit)
|
|
||||||
updateWorktime
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "Falsche angabe"
|
|
||||||
exit
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
## Umwandlung / Umrechnung
|
|
||||||
### Rechnet die Sekunden in Stunden und Minuten um
|
|
||||||
function calcWorktime {
|
|
||||||
if [ $1 -ge 3600 ]; then
|
|
||||||
hworktime=$((worktime / 3600))
|
|
||||||
mworktime=$(((worktime % 3600) / 60))
|
|
||||||
gmworktime=$((worktime / 60))
|
|
||||||
outputtime="$gmworktime min ($hworktime:$mworktime H)"
|
|
||||||
else
|
|
||||||
gmworktime=$((worktime / 60))
|
|
||||||
outputtime="$gmworktime min"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function convertDay {
|
|
||||||
case $1 in
|
|
||||||
1)
|
|
||||||
echo "Montag"
|
|
||||||
;;
|
|
||||||
2)
|
|
||||||
echo "Dienstag"
|
|
||||||
;;
|
|
||||||
3)
|
|
||||||
echo "Mittwoch"
|
|
||||||
;;
|
|
||||||
4)
|
|
||||||
echo "Donnerstag"
|
|
||||||
;;
|
|
||||||
5)
|
|
||||||
echo "Freitag"
|
|
||||||
;;
|
|
||||||
6)
|
|
||||||
echo "Samstag"
|
|
||||||
;;
|
|
||||||
7)
|
|
||||||
echo "Sonntag"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
# Argumente auslesen
|
|
||||||
#===============================
|
|
||||||
while getopts "Dc:e:hH:ilr:s:Tu:" opt; do
|
|
||||||
case $opt in
|
|
||||||
D)
|
|
||||||
showDB
|
|
||||||
exit
|
|
||||||
;;
|
|
||||||
c)
|
|
||||||
config
|
|
||||||
exit
|
|
||||||
;;
|
|
||||||
e)
|
|
||||||
erase
|
|
||||||
exit
|
|
||||||
;;
|
|
||||||
h)
|
|
||||||
printHelp
|
|
||||||
exit
|
|
||||||
;;
|
|
||||||
H)
|
|
||||||
helpTo $OPTARG
|
|
||||||
exit
|
|
||||||
;;
|
|
||||||
i)
|
|
||||||
insert
|
|
||||||
exit
|
|
||||||
;;
|
|
||||||
l)
|
|
||||||
while true; do
|
|
||||||
default
|
|
||||||
done
|
|
||||||
;;
|
|
||||||
r)
|
|
||||||
report
|
|
||||||
exit
|
|
||||||
;;
|
|
||||||
s)
|
|
||||||
search
|
|
||||||
exit
|
|
||||||
;;
|
|
||||||
T)
|
|
||||||
# Testing
|
|
||||||
results=($(sqlite3 $DBDIR "
|
|
||||||
SELECT *
|
|
||||||
FROM $DB
|
|
||||||
"))
|
|
||||||
|
|
||||||
#for i in ${!results[@]}; do
|
|
||||||
for i in "${!results[@]}"; do
|
|
||||||
echo "<================================================>"
|
|
||||||
echo "Test für: ${results[i]}"
|
|
||||||
|
|
||||||
echo "Record No. $i: ${results[$i]}"
|
|
||||||
|
|
||||||
|
|
||||||
fieldA=${results[0]};
|
|
||||||
fieldB=${results[1]};
|
|
||||||
fieldC=${results[2]};
|
|
||||||
fieldD=${results[3]};
|
|
||||||
|
|
||||||
done
|
|
||||||
|
|
||||||
echo $fieldA $fieldB $fieldC $fieldD
|
|
||||||
exit
|
|
||||||
;;
|
|
||||||
u)
|
|
||||||
update
|
|
||||||
exit
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
exit
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
default
|
|
||||||
Reference in New Issue
Block a user