save_recorded_time_in_table.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435
  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):
  8. return {'Name': NAME,
  9. 'Datum': str(datetime_functions.get_current_date()) ,
  10. 'Arbeitszeit' : worked_time,
  11. 'Einkommen': income,
  12. 'Kalenderwoche': datetime_functions.get_calendarweek_from_datetime(datetime_functions.get_current_date())}
  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 = calc_income_by_time_in_euro_without_sales_tax(worked_time_in_minutes, HOURLY_WAGE_IN_EURO)
  23. table_dict = create_recorded_time_dict(worked_time_in_minutes, income)
  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)