Advertisement
ksieradzinski

Untitled

Oct 27th, 2023
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. from csv import DictReader
  2. from datetime import datetime
  3.  
  4. from weasyprint import HTML
  5.  
  6.  
  7. # https://dokodu.it/zapisy/
  8.  
  9.  
  10. class PdfReport:
  11. def __init__(self):
  12. self.rows = []
  13.  
  14. def add_row(self, employee: str, hours:int, minutes:int):
  15. self.rows.append(
  16. f'<tr><td>{employee}</td><td>{hours} godzin {minutes} minut</td></tr>'
  17. )
  18.  
  19. def save(self, filename: str):
  20. content = f'''<table>
  21. <thead>
  22. <tr>
  23. <th>Pracownik</th>
  24. <th>Czas pracy</th>
  25. </tr>
  26. </thead>
  27. <tbody>
  28. {''.join(self.rows)}
  29. </tbody>
  30. </table>'''
  31.  
  32. html = HTML(string=content)
  33. html.write_pdf(filename)
  34.  
  35.  
  36. def read_file(filename: str):
  37. employee_report = {}
  38.  
  39. with open(filename, 'r', encoding='utf8') as file:
  40. reader = DictReader(file)
  41. for row in reader:
  42. start_date = datetime.strptime(row['Start Date'], '%Y-%m-%d %H:%M:%S')
  43. end_date = datetime.strptime(row['End Date'], '%Y-%m-%d %H:%M:%S')
  44. employee = row['Employee']
  45. customer = row['Client Name']
  46. time_delta = end_date - start_date
  47.  
  48. if employee in employee_report:
  49. employee_report[employee] += time_delta
  50. else:
  51. employee_report[employee] = time_delta
  52.  
  53. return employee_report
  54.  
  55.  
  56. report = read_file('logs.txt')
  57.  
  58. for employee, duration in report.items():
  59. hours, remainder = divmod(duration.total_seconds(), 3600)
  60. minutes, _ = divmod(remainder, 60)
  61. # print('Czas pracy', employee, int(hours), 'godzin', int(minutes), 'minut')
  62. print(f'Pracownik: {employee}, Czas pracy: {hours} godzin i {minutes} minut.')
  63.  
  64. # https://doc.courtbouillon.org/weasyprint/stable/first_steps.html
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement