inital timeTrack in python. write __init__ and load_config methode

This commit is contained in:
2021-05-09 18:53:06 +02:00
parent f2d11097a1
commit 7528fe8043

66
timeTrack.py Normal file
View File

@@ -0,0 +1,66 @@
#!/bin/python3
#########################
#
# timeTrack.py
# by 4nima
# v.0.0
#
#########################
# simple time tracking with database
#########################
import datetime
import sqlite3
import json
import os
import logging
class TimeTrack:
def __init__(self, DATABASE='timetrack.db', CONFIG='timetrack.conf'):
self.DATABASE = DATABASE
self.CONFIG = CONFIG
self.USER = 0
self.LOGFILE = 'timetrack.log'
logging.basicConfig(filename=self.LOGFILE,
level=logging.DEBUG,
format='%(asctime)s - %(process)d-%(levelname)s: %(message)s',
datefmt='%Y-%m-%d %H:%M:%S'
)
self.load_config()
## Läd oder erstellt das config file
def load_config(self):
if os.path.isfile(self.CONFIG):
logging.info('Config file found')
try:
with open(self.CONFIG) as config_data:
data = json.load(config_data)
except ValueError:
logging.error('Config file has no valid JSON syntax')
print('TimeTrack wird beendet. Fehler in der JSON-Konfig')
quit()
else:
logging.info('Config file loaded successfully')
self.USER = data['user']
else:
logging.info('Config file not found')
##> ausgabe nicht in einer zeile
config = {
'user' : 1,
'default' : 'interactive'
}
##> logging erweitert falls nicht möglich
with open(self.CONFIG, "w") as outfile:
json.dump(config, outfile)
logging.info('config file successfully created')
def db_connect(self):
pass
def set_user(self):
pass
test = TimeTrack()