Skip to content

Commit 15fa088

Browse files
committed
feat: Add core functionalities
1 parent 361bf9f commit 15fa088

28 files changed

+536
-5
lines changed

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
# ------------------ Project Specific ------------------
2+
3+
production/
4+
production/Certificate_Template.docx
5+
production/data.csv
6+
production/data.xlsx
7+
production/output/
8+
9+
# ------------------ Python Specific ------------------
10+
# Source: https://github.com/github/gitignore/blob/main/Python.gitignore
11+
112
# Byte-compiled / optimized / DLL files
213
__pycache__/
314
*.py[codz]

Certificate_Template.docx

13.4 KB
Binary file not shown.

data.csv

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
index,certificate_name,registration_email,other
2+
1,Example Name 1,example1@dileepa.dev,
3+
2,Example Name 2,example1@dileepa.dev,
4+
3,Example Name 3,example1@dileepa.dev,
5+
4,Example Name 4,example1@dileepa.dev,
6+
5,Example Name 5,example1@dileepa.dev,
7+
6,Example Name 6,example1@dileepa.dev,
8+
7,Example Name 7,example1@dileepa.dev,
9+
8,Example Name 8,example1@dileepa.dev,
10+
9,Example Name 9,example1@dileepa.dev,
11+
10,Example Name 10,example1@dileepa.dev,

data.xlsx

9.92 KB
Binary file not shown.

main.py

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,57 @@
1-
def main():
2-
print("Hello from python-certificate-generator!")
1+
import os
2+
from docxtpl import DocxTemplate
3+
from docx2pdf import convert
4+
import pandas as pd
35

6+
ans = pd.read_csv("data.csv")
7+
n = len(ans)
48

5-
if __name__ == "__main__":
6-
main()
9+
output_folder = "output"
10+
if not os.path.exists(output_folder):
11+
os.makedirs(output_folder)
12+
13+
14+
def generate_certificate(index, total_rows):
15+
tpl = DocxTemplate("Certificate_Template.docx")
16+
17+
# Extracting relevant information for the current row
18+
# fName = ans["FName"][index - 1]
19+
# lName = ans["LName"][index - 1]
20+
certificate_name = ans["certificate_name"][index - 1]
21+
# registration_email = ans["registration_email"][index - 1]
22+
# user_id = ans["ID"][index - 1]
23+
# get user_id as the index
24+
user_id = index
25+
26+
# Creating the context dictionary
27+
context = {
28+
j + 1: {
29+
# "FName": fName,
30+
# "LName": lName,
31+
"certificate_name": certificate_name,
32+
# "ID": user_id,
33+
}
34+
for j in range(index)
35+
}
36+
37+
tpl.render(context[index])
38+
39+
output_path_docx = os.path.join(
40+
output_folder,
41+
# Below are extras
42+
# f"{fName}{lName}.docx",
43+
# f"{certificate_name}.docx",
44+
f"{index} - {certificate_name}.docx",
45+
)
46+
tpl.save(output_path_docx)
47+
48+
print(
49+
f"Processing file: {index}/{total_rows} | {user_id} - {certificate_name}")
50+
convert(output_path_docx)
51+
52+
53+
# Loop through all records and generate certificates
54+
for i in range(1, n + 1):
55+
generate_certificate(i, n)
56+
57+
print("All done!")

output/1 - Example Name 1.docx

11.4 KB
Binary file not shown.

output/1 - Example Name 1.pdf

26.6 KB
Binary file not shown.

output/10 - Example Name 10.docx

11.4 KB
Binary file not shown.

output/10 - Example Name 10.pdf

27.1 KB
Binary file not shown.

output/2 - Example Name 2.docx

11.4 KB
Binary file not shown.

0 commit comments

Comments
 (0)