save_recorded_time_in_table.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. from time_recoder.time_recoder_config import HOURLY_WAGE_IN_EURO, PATH, NAME
  2. from personal_income_calculator.income_calculator_main import calc_income_by_time_in_euro
  3. from tool_lib import create_excel_tables
  4. from os import path
  5. from time import time
  6. from datetime import date
  7. def create_recorded_time_dict(worked_time, income, sales_taxes):
  8. return {'Name': NAME,
  9. 'Datum': str(date.today()),
  10. 'Arbeitszeit' : worked_time,
  11. 'Einkommen': income,
  12. 'Umsatzsteuern': sales_taxes}
  13. def table_exists(path_):
  14. return path.isfile(path_)
  15. def get_current_time_as_timestamp():
  16. return int(time())
  17. def add_to_xlsx_table(table_object):
  18. table_object.append_df_to_xlsx(table_object.dataframes)
  19. def create_xlsx_table(table_object):
  20. table_object.export_to_excel(table_object.create_writer())
  21. def save_recorded_time_in_table(worked_time_in_minutes):
  22. income, sales_taxes = calc_income_by_time_in_euro(worked_time_in_minutes, HOURLY_WAGE_IN_EURO)
  23. table_dict = create_recorded_time_dict(worked_time_in_minutes, income, sales_taxes)
  24. xlsx_table = create_excel_tables.CreateTable(table_dict, path=PATH)
  25. if table_exists(PATH):
  26. add_to_xlsx_table(xlsx_table)
  27. else:
  28. create_xlsx_table(xlsx_table)