-
Notifications
You must be signed in to change notification settings - Fork 0
/
base_create.py
209 lines (124 loc) · 3.98 KB
/
base_create.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
#!/usr/bin/python3
from field import *
BASELINESKIP = .5
latex_replacements = {"~":"$\sim$","&":"\\&"}
def load_fields(file_name,replacement_dict={}):
"""
Input: file_name -> string: location of data file.
Output: dicitonary -> key: keyword given in file (lower case)
value: Instance of Field class
"""
fil = open(file_name,'r')
data = fil.read().replace('\n','')
fil.close()
d = [elm.lstrip('[') for elm in data.split(']') if elm!='']
field_list = []
for entry in d:
e = [[t.strip().lower() for t in elm.split("=")] for elm in entry.split(";") if elm != '']
tmp_dict = {}
for key,value in e:
tmp_dict[key] = value
field_list.append(tmp_dict)
for field in field_list:
field['required'] = [elm for elm in field['required'].split(',') if elm != '']
try:
field['optional'] = [elm for elm in field['optional'].split(',') if elm != '']
except KeyError:
pass
out = {}
for field in field_list:
keyword = field['keyword']
if keyword in out:
raise KeyError("'{0}' already exists as a keyword".format(keyword))
out[keyword] = Field(field,replacement_dict)
return out
def load_data(file_name,fields):
"""
Input: file_name -> string: location of data file.
Output: dicitonary -> key: keyword given in file (lower case)
value: list of dicionaries of data
"""
fil = open(file_name,'r')
data = fil.read().replace('\n','')
fil.close()
d = [elm.lstrip('{') for elm in data.split('}') if elm!='']
out = {}
for key in fields:
out[key] = []
for entry in d:
e = [[t.strip() for t in elm.split("=")] for elm in entry.split(";") if elm != '']
tmp_dict = {}
for key,value in e:
tmp_dict[key.lower()] = value
keyword = tmp_dict['keyword']
field = fields[keyword]
out[keyword].append(field(tmp_dict))
return out
class CV(object):
def __init__(self,data_file,formatting_file,HTML = False):
self.fields = load_fields(formatting_file,latex_replacements)
self.data = load_data(data_file,self.fields)
#for key in self.data:
# self.data[key].sort(key=entry_order)
#Add keyword:Section names here. Order is unimportant.
self.sections = { 'education':"Education",
'address':"Address",
'publication':"Publications",
'work experience':"Work Experience",
'award':"Awards and Honors",
'grant':"Grants",
'talk conference':"Presentations",
'conference':"Workshops and Conferences",
'organization':"Organizations",
'undergraduate research':"Undergraduate Research",
'poster':"Selected Posters",
'undergraduate presentation':"Selected Undergraduate Presentations",
'outreach':"Outreach",
'mentoring':"Mentoring",
}
#Move stuff around here to change order, or comment out to remove.
self.cv_order = [ 'address',
'education',
'work experience',
'mentoring',
'outreach',
'award',
'grant',
'publication',
'talk conference',
'conference',
'organization',
'undergraduate research',
'poster',
'undergraduate presentation'
]
def create_cv(self,output_file):
head = open("header.tex",'r')
cv = head.read()
head.close()
for key in self.cv_order:
self.data[key].sort(reverse = True)
if all([not self.to_appear(elm) for elm in self.data[key]]):
continue
#Change this line to change section styles.
cv += "\\section{{\\textbf{{\\large {0}}}}}".format(self.sections[key])
if key not in self.data:
continue
for d in self.data[key]:
if self.to_appear(d):
cv += str(d)
cv += "\\vspace{{{0}\\baselineskip}}\n\n\n".format(BASELINESKIP)
cv += "\n\n\n"
foot = open('footer.tex','r')
cv += foot.read()
foot.close()
out = open(output_file,'w')
out.write(cv)
out.close()
def to_appear(self,data):
return data.show
if __name__=='__main__':
formatting_file= "cv_formatting.txt"
data_file = "cv_data.txt"
test = CV(data_file,formatting_file)
test.create_cv('output/cv.tex')