-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrender_cv.py
168 lines (152 loc) · 5.37 KB
/
render_cv.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import pandas as pd
from jinja2 import Environment, FileSystemLoader
import re
import pdfkit
# Load CSV data
csv_file = 'cv_data.csv'
df = pd.read_csv(csv_file)
# Organize data into sections
def organize_data(df):
sections = {}
for _, row in df.iterrows():
section = row['Section']
if section not in sections:
sections[section] = []
subsection = row['Subsection']
detail = row['Detail']
# Replace incorrect symbols in dates
subsection = subsection.replace('–', '–').replace('—', '—')
detail = detail.replace('–', '–').replace('—', '—')
# Check if the subsection or detail contains a link placeholder and make it clickable
link_match_subsection = re.search(r'\[(.+)\]\((https?://\S+)\)', subsection)
if link_match_subsection:
link_text = link_match_subsection.group(1)
link_url = link_match_subsection.group(2)
if 'github.com' in link_url:
subsection = re.sub(r'\[(.+)\]\((https?://\S+)\)', f'<a href="{link_url}" target="_blank">{link_text} <img src="https://img.icons8.com/ios-glyphs/30/000000/github.png" alt="GitHub" width="16" height="16"></a>', subsection)
else:
subsection = re.sub(r'\[(.+)\]\((https?://\S+)\)', f'<a href="{link_url}" target="_blank">{link_text}</a>', subsection)
link_match_detail = re.search(r'\[(.+)\]\((https?://\S+)\)', detail)
if link_match_detail:
link_text = link_match_detail.group(1)
link_url = link_match_detail.group(2)
detail = re.sub(r'\[(.+)\]\((https?://\S+)\)', f'<a href="{link_url}" target="_blank">{link_text}</a>', detail)
sections[section].append({'Subsection': subsection, 'Detail': detail})
return sections
sections = organize_data(df)
# Setup Jinja2 environment for HTML templating
env = Environment(loader=FileSystemLoader('.'))
# Render the CV HTML
remove_icons = False
# Check if the rendering is for PDF
pdf_rendering = True
if pdf_rendering:
remove_icons = True
# Render the CV HTML
template_str = '''
<!DOCTYPE html>
<html>
<head>
<title>Valentin Kriegmair Resume - CV</title>
<meta charset="UTF-8">
<link rel="stylesheet" href="style.css">
<style>
body {
font-family: 'Helvetica', sans-serif;
color: #333;
background-color: #ffffff;
line-height: 1.6;
margin: 0;
padding: 0 20px;
}
h1 {
font-size: 36px;
color: #222;
margin-bottom: 10px;
}
.contact-info p {
margin: 2px 0;
font-size: 14px;
}
h2 {
font-size: 24px;
color: #444;
border-bottom: 2px solid #ddd;
padding-bottom: 5px;
margin-top: 30px;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 15px;
}
table td {
padding: 10px;
vertical-align: top;
}
a {
text-decoration: none;
color: #0077b5;
}
a:hover {
text-decoration: underline;
}
img {
vertical-align: middle;
margin-right: 5px;
width: 16px;
height: 16px;
}
.contact-info {
margin-bottom: 20px;
}
.contact-info a {
margin-right: 15px;
}
</style>
</head>
<body>
<h1 style="text-align: left;">Valentin Kriegmair</h1>
<div class="contact-info" style="text-align: left;">
<p>Urbanstrasse 36b | 10967 Berlin</p>
<p>[email protected] | 015119090065</p>
<p>
<a href="https://github.com/valentinkm" target="_blank">GitHub{% if not remove_icons %}<img src="https://img.icons8.com/ios-glyphs/30/000000/github.png" alt="GitHub" width="16" height="16">{% endif %}</a>
<a href="https://www.linkedin.com/in/valentin-kriegmair-a12b4b269" target="_blank" style="margin-left: 15px;">LinkedIn{% if not remove_icons %}<img src="https://img.icons8.com/ios-glyphs/30/000000/linkedin.png" alt="LinkedIn" width="16" height="16">{% endif %}</a>
</p>
</div>
{% for section, items in sections.items() %}
<h2>{{ section }}</h2>
<table>
{% for item in items %}
<tr>
<td style="width: 30%; font-weight: bold;">{{ item['Subsection'] | safe }}</td>
<td style="width: 70%;">{{ item['Detail'] | safe }}</td>
</tr>
{% endfor %}
</table>
<br>
{% endfor %}
<div style="text-align: center; margin-top: 20px;">
<a href="cv.pdf" target="_blank">Download PDF Version of CV</a>
</div>
</body>
</html>
'''
html_template = env.from_string(template_str)
html_output = html_template.render(sections=sections, remove_icons=remove_icons)
# Save the rendered HTML to a file
with open('cv.html', 'w', encoding='utf-8') as f:
f.write(html_output)
print("HTML CV generated as 'cv.html'")
# Convert the CV HTML file to PDF using pdfkit
try:
options = {
'quiet': '',
'enable-local-file-access': None,
'encoding': 'UTF-8'
}
pdfkit.from_file('cv.html', 'cv.pdf', options=options)
print("CV PDF generated as 'cv.pdf'")
except Exception as e:
print(f"An error occurred while generating the PDF: {e}")