-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcv.py
50 lines (33 loc) · 1.32 KB
/
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
from glob import glob
from pathlib import Path
import sys
import json
def main():
with open('sections.json', 'r') as f:
sections_dict = json.load(f)
for section_dict in sections_dict:
s = Section(**section_dict)
s.output()
#with open('cv.tex.pieces/experience.tex', 'w') as f:
# f.write('\n\n'.join(Experience(Path(x)).compile()
# for x in sorted(list(exp_dir.glob('*')))))
class Section():
def __init__(self, **kwargs):
self.name = kwargs['section_name']
self.tex_cmd = kwargs['tex_cmd']
self.path = Path(kwargs['path'])
self.fields = kwargs['fields']
self.items = [Path(x) for x in sorted(glob(str(self.path) + '/*/'))]
self.tex = self.compile()
def compile_item(self, item):
return '\\' + self.tex_cmd + '{' + '}{'.join(self.compile_field(item, field) for field in self.fields) + '}'
def compile_field(self, item, field):
with open(item / (field + '.tex'), 'r') as f:
return f.read()
def compile(self):
return '\\section{' + self.name + '}' + '\n\n'.join(self.compile_item(i) for i in self.items)
def output(self):
with open(Path('compiled_sections') / (self.name + '.tex'), 'w') as f:
f.write(self.tex)
if __name__ == '__main__':
main()