from time_recoder.time_recoder_config import HOURLY_WAGE_IN_EURO, PATH, NAME from personal_income_calculator.income_calculator_main import calc_income_by_time_in_euro_without_sales_tax from tool_lib import datetime_functions from tool_lib import create_excel_tables from os import path from time import time def create_recorded_time_dict(worked_time, income, task): return {'Name': NAME, 'Datum': datetime_functions.datetime_to_str(datetime_functions.get_current_date(),'%d/%m/%Y') , 'Arbeitszeit': worked_time, 'Einkommen': income, 'Kalenderwoche': datetime_functions.datetime_to_str(datetime_functions.get_current_date(), '%V'), 'Task': task} def table_exists(path_): return path.isfile(path_) def get_current_time_as_timestamp(): return int(time()) def add_to_xlsx_table(table_object): table_object.append_df_to_xlsx(table_object.dataframes) def create_xlsx_table(table_object): table_object.export_to_excel(table_object.create_writer()) def save_recorded_time_in_table(worked_time_in_minutes, task): worked_time_in_minutes = round(worked_time_in_minutes) income = calc_income_by_time_in_euro_without_sales_tax(worked_time_in_minutes, HOURLY_WAGE_IN_EURO) table_dict = create_recorded_time_dict(worked_time_in_minutes, income, task) xlsx_table = create_excel_tables.CreateTable(table_dict, path=PATH) if table_exists(PATH): add_to_xlsx_table(xlsx_table) else: create_xlsx_table(xlsx_table)