-
Notifications
You must be signed in to change notification settings - Fork 12
/
main.py
138 lines (104 loc) · 4.04 KB
/
main.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
from docx import Document
from docx.shared import Inches, Cm
# from docx.enum.text import WD_ALIGN_PARAGRAPH
from docx.shared import Pt
import datetime
import json, re, os
from pprint import pprint
import helper
############## CONFIG
# detail file goes here
info = "sample.json"
save_dir = "./"
data = json.load(open(info))
name = data["name"]
address = data["address"]
phone = data["phone"]
email = data["email"]
website= data["website"]
github= data["github"]
data["company_name"] = helper.askInput("Enter name of the company:")
company_name=data["company_name"]
data["position"] = helper.askInput("Enter the position name: ")
position=data["position"]
open_para=data["open_para"]
first_coop=data["first_coop"]
second_coop=data["second_coop"]
third_coop=data["third_coop"]
activities=data["activities"]
closing=data["closing"]
document = Document()
document.add_heading(name, 2)
margin = 2
#changing the page margins
sections = document.sections
for section in sections:
section.top_margin = Cm(margin)
section.bottom_margin = Cm(margin)
section.left_margin = Cm(margin)
section.right_margin = Cm(margin)
contact_info = document.add_paragraph()
#Contact information
address_obj = contact_info.add_run(address + " , ")
phone_obj = contact_info.add_run(phone + " , ")
mail_obj = contact_info.add_run(email)
website_obj = contact_info.add_run("\n" + "Website:" + website)
github_obj = contact_info.add_run("\n" + "Github:" + github)
document.add_heading("_" * 90, 6)
# datetime
today = datetime.datetime.today()
date_obj = document.add_paragraph().add_run(today.strftime('%d, %b %Y'))
re_obj = document.add_paragraph()
re_obj.add_run("Re: " + position)
dear_obj = document.add_paragraph()
dear_obj.add_run("Dear Hiring Manager,")
#Open paragraph
openpara_obj = document.add_paragraph()
openpara_obj = helper.format_alignment(openpara_obj)
open_para_choice = helper.askForChoice(open_para, "Choose open paragraph")
openpara_obj.add_run(helper.format_fill_in_info(open_para_choice, data))
#Third coop
third_coop_obj = document.add_paragraph()
third_coop_obj = helper.format_alignment(third_coop_obj)
third_coop_obj.add_run(third_coop)
#Second coop
second_coop_obj = document.add_paragraph()
second_coop_obj.add_run(second_coop)
second_coop_obj = helper.format_alignment(second_coop_obj)
#First coop
first_coop_obj = document.add_paragraph()
first_coop_obj = helper.format_alignment(first_coop_obj)
first_coop_obj.add_run(first_coop)
##############ACTIVITIES
activities_obj = document.add_paragraph()
activities_obj = helper.format_alignment(activities_obj)
activities = helper.askForChoices(activities, "Choose extracurricular activities")
activity_string = "Beside coop experience, {}. Additionally, {}. {}. Last but not least, {}."
activities = {'a': '1', 'b': '2', 'c': '3', 'd': '4'}
activiy_para = activity_string.format(*activities)
activities_obj.add_run(activiy_para)
##############FINAL PARAGRAPH
final_obj = document.add_paragraph()
final_obj = helper.format_alignment(final_obj)
final_obj.add_run(helper.format_fill_in_info(closing, data))
availability = helper.askYesNo("Availability: options are (4, 8, 12 or 16) months. n for no")
if availability:
data["availability_time"] = availability
final_obj.add_run(helper.format_fill_in_info(data["available"], data))
##############CLOSING
closing_obj= document.add_paragraph()
closing_obj = helper.format_alignment(closing_obj, 0)
closing_obj.add_run("Sincerely,")
##############SIGNATURE
name_obj= document.add_paragraph()
name_obj = helper.format_alignment(name_obj, 0)
name_obj.add_run(name)
# save_file_name = company_name.strip(" ") + "-" + position.strip(" ") + today.strftime('%d, %b %Y').strip(" ") + ".docx"
save_file_name = helper.sanitize_name([company_name, position, today.strftime('%d, %b %Y') ])
save_to_path = save_dir + save_file_name
print("Save to:", save_to_path)
document.save(save_to_path)
os.system("abiword --to=pdf " + save_to_path) # Convert to pdf using abiword
os.system("rm -rf " + save_to_path) # Delete the doc file
with open(info, 'w') as outfile:
json.dump(data, outfile, indent=4)