forked from eventuallyc0nsistent/gen-cover-letter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgencovletter.py
68 lines (54 loc) · 1.99 KB
/
gencovletter.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
""""
Use notepad++ to save the txt file as ISO-8859-1 encoding
"""
from fpdf import FPDF
from ftfy import fix_text
import time
import os
line_height = 6
def write_cover_letter(customization):
pdf = FPDF('P', 'mm', 'Letter') # portrait mode, mm , A4 size paper
pdf.add_page() # new blank page
pdf.set_font('Times', '', 12) # font, Style (B,U,I) , fontsize in pt.
model_cover_letter = open("cover_letter.txt", 'r', encoding="ISO-8859-1")
for line in model_cover_letter:
line = fix_text(line)
for key, value in customization.items():
full_variable_name = "#" + key
line = line.replace(full_variable_name, value)
if "https:" not in line:
pdf.write(line_height, line) # 6 is line height
else:
link_idx = line.find("https:")
before_link = line[:link_idx]
after_link = line[link_idx:].strip()
pdf.write(line_height, before_link)
pdf.set_text_color(0, 0, 255)
pdf.set_font('', 'U')
pdf.write(line_height, line[link_idx:], link=after_link)
pdf.set_text_color(0, 0, 0)
pdf.set_font('', '')
file_name = customization["file_name"]
# windows
# try:
# pdf.output(file_name + '.pdf', 'F')
# except:
# os.system("taskkill /im Acrobat.exe")
# time.sleep(1)
# pdf.output(file_name + '.pdf', 'F')
os.system("killall -KILL AdobeAcrobat") # for mac
time.sleep(1)
pdf.output(file_name + '.pdf', 'F')
pdf.close()
if __name__ == "__main__":
customization = {
"file_name": 'Zack_Light_Cover_Letter',
"company": "DRW",
"position": "the Trading Systems Engineer (Algo) position",
# "field": "software engineering",
# "field": "data science",
# "period": "the summer of 2020",
# "skills": "natural language processing",
}
write_cover_letter(customization)
os.system("open " + customization["file_name"] + '.pdf')