-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_resume.py
More file actions
327 lines (282 loc) · 9.4 KB
/
generate_resume.py
File metadata and controls
327 lines (282 loc) · 9.4 KB
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
#!/usr/bin/env python3
"""
Resume Generator - Convert YAML resume to PDF
Usage: python generate_resume.py
"""
import yaml
from jinja2 import Template
from weasyprint import HTML
import os
import re
def parse_markdown_links(text):
"""Convert Markdown-style links [text](url) to HTML <a> tags."""
if not text:
return text
# Regex to match [text](url)
pattern = r'\[([^\]]+)\]\(([^\)]+)\)'
return re.sub(pattern, r'<a href="\2">\1</a>', text)
def convert_hyphens(text):
"""
Converts standard hyphen-minus (-) used in date ranges to the
typographically correct en dash (–).
This is applied specifically to date fields.
"""
if not text:
return text
# Replace single hyphen-minus with en dash, but only if preceded/followed by a word character
# (to avoid replacing hyphens in compound words unnecessarily, though dates are the primary target).
# A simple replacement for date ranges should be sufficient and safe.
return text.replace('-', '–')
# HTML/CSS template matching your current resume style
TEMPLATE = """
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Maximillian V. Phillips</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
<style>
@page {
size: letter;
margin: 0;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: "Helvetica Neue", Helvetica, Arial, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
font-size: 11pt;
line-height: 1.4;
color: #000;
margin: 0.75in 0.75in;
}
.header {
text-align: center;
margin-bottom: 8pt;
}
.header h1 {
font-size: 16pt;
font-weight: 700;
margin-bottom: 2pt;
letter-spacing: 0.02em;
}
.header .contact {
font-size: 11pt;
font-weight: 400;
}
.section {
margin-bottom: 10pt;
}
.section-title {
font-size: 11pt;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0.05em;
margin-bottom: 4pt;
padding-bottom: 2pt;
border-bottom: 0.5pt solid #000;
}
a {
color: #000;
text-decoration: none;
border-bottom: 1px dotted #999;
}
a:hover {
background-color: #f0f0f0;
}
/* --- SKILLS SECTION FIX --- */
.skills-list {
/* Now an actual unordered list for proper bullet control */
list-style: disc;
/* Indent the whole list slightly for visual space */
margin-left: 10pt;
padding-left: 0;
list-style-position: outside; /* Ensure wrapped text aligns correctly */
}
.skill-item {
margin-bottom: 3pt;
/* Using list-style takes care of the indent automatically */
margin-left: 10pt;
padding-left: 0;
}
/* -------------------------- */
.experience-item, .education-item, .project-item {
margin-bottom: 8pt;
}
.company-header {
display: flex;
justify-content: space-between;
align-items: baseline;
margin-bottom: 0pt;
font-weight: 600;
}
.company-name {
font-weight: 600;
}
.company-dates {
font-weight: 400;
font-style: italic;
}
.role-item {
margin-left: 0;
margin-bottom: 4pt;
}
.role-header {
display: flex;
justify-content: space-between;
align-items: baseline;
font-weight: 400;
margin-top: 1pt;
}
.role-dates {
font-style: italic;
font-weight: 400;
font-size: 10pt;
}
.responsibilities {
margin-left: 12pt;
margin-top: 1pt;
}
.responsibilities li {
margin-bottom: 1pt;
}
.project-header {
margin-bottom: 1pt;
}
.project-name {
font-weight: 600;
display: inline;
}
.project-tech {
font-style: italic;
display: inline;
}
.project-url {
float: right;
font-style: italic;
}
.coursework {
margin-left: 12pt;
}
.education-header {
display: flex;
justify-content: space-between;
align-items: baseline;
margin-bottom: 1pt;
}
.institution {
font-weight: 600;
}
.degree-line {
margin-bottom: 1pt;
}
</style>
</head>
<body>
<div class="header">
<h1>{{ name }}</h1>
<div class="contact">{{ parse_links(location) }} — {{ parse_links(email) | safe }} — {{ parse_links(website) | safe }}</div>
</div>
<div class="section">
<div class="section-title">Skills</div>
<ul class="skills-list">
{% for skill in skills %}
<li class="skill-item"><strong>{{ skill.category }}:</strong> {% for item in skill.get('items', []) %}{{ parse_links(item) | safe }}{% if not loop.last %}, {% endif %}{% endfor %}</li>
{% endfor %}
</ul>
</div>
<div class="section">
<div class="section-title">Experience</div>
{% for job in experience %}
<div class="experience-item">
{% for role in job.roles %}
<div class="role-item">
<div class="role-header">
<span style="font-weight: 600;">{{ parse_links(role.title) | safe }}</span>
<span class="role-dates">{{ convert_hyphens(role.dates) }}</span>
</div>
<div style="margin-bottom: 2pt;">{{ parse_links(job.company) | safe }} • {{ job.location }}</div>
<ul class="responsibilities">
{% for resp in role.responsibilities %}
<li>{{ parse_links(resp) | safe }}</li>
{% endfor %}
</ul>
</div>
{% endfor %}
</div>
{% endfor %}
</div>
<div class="section">
<div class="section-title">Awards</div>
{% for award in awards %}
<div class="experience-item">
<div class="role-header">
<span style="font-weight: 600;">{{ parse_links(award.name) | safe }}</span>
<span class="role-dates">{{ convert_hyphens(award.date) }}</span>
</div>
<div style="margin-bottom: 2pt;">{{ parse_links(award.organization) | safe }}{% if award.team %} • {{ award.team }}{% endif %}</div>
{% if award.description %}
<ul class="responsibilities">
<li>{{ parse_links(award.description) | safe }}</li>
</ul>
{% endif %}
</div>
{% endfor %}
</div>
<div class="section">
<div class="section-title">Education</div>
{% for edu in education %}
<div class="education-item">
<div class="education-header">
<span class="institution">{{ parse_links(edu.degree) | safe }}</span>
<span style="font-style: italic;">{{ convert_hyphens(edu.graduation) }}</span>
</div>
<div style="margin-bottom: 2pt;">{{ parse_links(edu.institution) | safe }}{% if edu.gpa %} • {{ edu.gpa }}{% endif %}</div>
{% if edu.coursework %}
<div class="coursework">
<strong>• Coursework:</strong> {% for course in edu.coursework %}{{ parse_links(course) | safe }}{% if not loop.last %}, {% endif %}{% endfor %}
</div>
{% endif %}
</div>
{% endfor %}
</div>
</body>
</html>
"""
def generate_resume(yaml_file='resume.yaml', output_pdf='resume.pdf', output_html='resume.html'):
"""Generate PDF and HTML resume from YAML file."""
if not os.path.exists(yaml_file):
print(f"Error: {yaml_file} not found. Please create the file first.")
return
# Load YAML data
try:
with open(yaml_file, 'r') as f:
data = yaml.safe_load(f)
except yaml.YAMLError as e:
print(f"Error parsing YAML: {e}")
return
# Render template
template = Template(TEMPLATE)
# Add the custom functions to Jinja2 environment
template.globals['parse_links'] = parse_markdown_links
template.globals['convert_hyphens'] = convert_hyphens
html_content = template.render(**data)
# Generate HTML file
try:
with open(output_html, 'w', encoding='utf-8') as f:
f.write(html_content)
print(f"✓ HTML generated: {output_html}")
except Exception as e:
print(f"Error generating HTML: {e}")
# Generate PDF
try:
HTML(string=html_content).write_pdf(output_pdf)
print(f"✓ PDF generated: {output_pdf}")
except Exception as e:
print(f"Error generating PDF: {e}")
if __name__ == '__main__':
generate_resume()