save_recorded_time_in_table.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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_without_sales_tax
  3. from tool_lib import datetime_functions
  4. from tool_lib import create_excel_tables
  5. from os import path
  6. from time import time
  7. def create_recorded_time_dict(worked_time, income, task):
  8. return {'Name': NAME,
  9. 'Datum': datetime_functions.datetime_to_str(datetime_functions.get_current_date(),'%d/%m/%Y') ,
  10. 'Arbeitszeit': worked_time,
  11. 'Einkommen': income,
  12. 'Kalenderwoche': datetime_functions.datetime_to_str(datetime_functions.get_current_date(), '%V'),
  13. 'Task': task}
  14. def table_exists(path_):
  15. return path.isfile(path_)
  16. def get_current_time_as_timestamp():
  17. return int(time())
  18. def add_to_xlsx_table(table_object):
  19. table_object.append_df_to_xlsx(table_object.dataframes)
  20. def create_xlsx_table(table_object):
  21. table_object.export_to_excel(table_object.create_writer())
  22. def save_recorded_time_in_table(worked_time_in_minutes, task):
  23. worked_time_in_minutes = round(worked_time_in_minutes)
  24. income = calc_income_by_time_in_euro_without_sales_tax(worked_time_in_minutes, HOURLY_WAGE_IN_EURO)
  25. table_dict = create_recorded_time_dict(worked_time_in_minutes, income, task)
  26. xlsx_table = create_excel_tables.CreateTable(table_dict, path=PATH)
  27. if table_exists(PATH):
  28. add_to_xlsx_table(xlsx_table)
  29. else:
  30. create_xlsx_table(xlsx_table)