forked from Sabyasachi-Seal/Certificate-Generator-MLSA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_certificate.py
66 lines (45 loc) · 1.89 KB
/
main_certificate.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
import os
os.system("pip install -r requirements.txt")
from certificate import *
from docx import Document
import csv
from docx2pdf import convert
# create output folder if not exist
try:
os.makedirs("Output/Doc")
os.makedirs("Output/PDF")
except OSError:
pass
def get_participants(f):
data = [] # create empty list
with open(f, mode="r", encoding='utf-8') as file:
csv_reader = csv.DictReader(file)
for row in csv_reader:
data.append(row) # append all results
return data
def create_docx_files(filename, list_participate, ambassador):
for participate in list_participate:
# use original file everytime
doc = Document(filename)
name = participate["Name Surname"]
event = participate["Workshop"]
replace_participant_name(doc, name)
replace_event_name(doc, event)
replace_ambassador_name(doc, ambassador)
doc.save('Output/Doc/{}.docx'.format(name))
# ! if your program working slowly, comment this two line and open other 2 line.
print("Output/{}.pdf Creating".format(name))
convert('Output/Doc/{}.docx'.format(name), 'Output/Pdf/{}.pdf'.format(name))
# ! Open those lines and comment above 2 lines if your program working extremely slow
# os.system("docx2pdf Output/Doc/")
# os.system("move Output\Doc\*pdf Output\PDF")
# get certificate temple path
certificate_file = "Data/Event Certificate Template.docx"
# get participants path
participate_file = "Data/"+("Participant List.csv" if (input("Test Mode (Y/N): ").lower())[0]=="n" else "temp.csv")
# Enter your name here [Ambassador Name]
ambassador_name = input("Enter your name(This will be the host name on the certificates): ")
# get participants
list_participate = get_participants(participate_file);
# process data
create_docx_files(certificate_file, list_participate, ambassador_name)