-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathpkup_doc.py
executable file
·118 lines (99 loc) · 3.89 KB
/
pkup_doc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
# this is a script generating *.docx Word document with PKUP report
from __future__ import unicode_literals
from docx import Document
from docx.shared import Inches
from datetime import date, datetime, timedelta
import sys, getopt
def generate_report():
create_document()
set_file_path()
generate_heading()
generate_dates()
generate_personal_data()
generate_work_results()
generate_legal_text()
save_report()
def create_document():
global document
document = Document()
def set_file_path():
global dir_path
dir_path = './'
def generate_heading():
document.add_heading('Raport Miesięczny Pracy Twórczej', 0)
def generate_dates():
generate_bold_text('Okres')
table = document.add_table(rows=2, cols=2)
table.style = 'Table Grid'
date_twenty_days_ago = datetime.today() - timedelta(days=20)
month_twenty_days_ago = add_zero_prefix(date_twenty_days_ago.month)
from_date = "19.%s.%d" % (month_twenty_days_ago, date_twenty_days_ago.year)
to_date = date.today().strftime('%d.%m.%Y')
date_range = "%s - %s" % (from_date, to_date)
set_row(table, 0, "Okres raportowany od 19 do 18 dnia miesiąca", date_range)
set_row(table, 1, "Data sporządzenia raportu", to_date)
def add_zero_prefix(number):
return "0%d" % number if(number < 10) else "%d" % number
def generate_personal_data():
generate_bold_text('Dane osobowe')
table = document.add_table(rows=4, cols=2)
table.style = 'Table Grid'
set_row(table, 0, "Imię i nazwisko pracownika", employee_name)
set_row(table, 1, "Stanowisko służbowe", employee_role)
set_row(table, 2, "Dział", employee_dept)
set_row(table, 3, "Imię i nazwisko przełożonego pracownika", employee_mgr)
def generate_work_results():
generate_bold_text('Raportowane wyniki pracy twórczej')
table = document.add_table(rows=3, cols=2)
table.style = 'Table Grid'
set_row(table, 0, "Rodzaj wyniku pracy twórczej", "Opis wykonywanych czynności")
set_row(table, 1, "Prace przygotowawcze","")
set_row(table, 2, "Prace programistyczne i specyfikacja techniczna", report_text)
def set_row(table, row_number, label, value):
table.rows[row_number].cells[0].text = label
table.rows[row_number].cells[1].text = value
def generate_legal_text():
text = "Załącznik nr. 1 do Regulaminu Działalności Twórczej z dnia 28.12.2007"
generate_bold_text(text)
def generate_bold_text(text):
paragraph = document.add_paragraph()
paragraph.add_run('\n' + text).bold = True
def save_report():
name, surname = employee_name.split(" ")
doc_prefix = (name[:1] + surname[:2]).upper()
current_month = add_zero_prefix(date.today().month)
file_name = "%s_raport_pkup_%s_%d.docx" % (doc_prefix, current_month, date.today().year)
full_file_path = dir_path + file_name
document.save(full_file_path)
print('report saved successfully to: %s' % (full_file_path))
def main(argv):
global employee_name
global employee_role
global employee_dept
global employee_mgr
global report_text
help_message = 'pkup_doc.py -n <name and surname> -r <role> -d <department> -m <manager> -t <text>'
try:
opts, args = getopt.getopt(argv,"n:r:d:m:t",["name=","role=","department=","manager=","text="])
except getopt.GetoptError:
print(help_message)
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print(help_message)
sys.exit()
elif opt in ("-n", "--name"):
employee_name = arg
elif opt in ("-r", "--role"):
employee_role = arg
elif opt in ("-d", "--department"):
employee_dept = arg
elif opt in ("-m", "--manager"):
employee_mgr = arg
elif opt in ("-t", "--text"):
report_text = arg
generate_report()
if __name__ == "__main__":
main(sys.argv[1:])