-
Notifications
You must be signed in to change notification settings - Fork 0
/
webresume.py
166 lines (116 loc) · 4.45 KB
/
webresume.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
from jinja2 import Template
from datetime import date
import time
import json
import math
import hashlib
import webcolors
from collections import namedtuple
DATE_FORMAT = "%Y, %m, %d"
def parse_date(string, format):
raw_time = time.strptime(string, format)
return date(raw_time.tm_year, raw_time.tm_mon, raw_time.tm_mday)
def parse_json(filename):
with open(filename) as j:
data_dict = json.load(j)
print(data_dict)
def hash_color_tint(string, rgb_tint):
h = hashlib.new("sha1")
h.update(string)
hex_color = "#{}".format(str(h.hexdigest()[:6]))
rgb_color = webcolors.hex_to_rgb(hex_color)
def avg2(a, b):
return (a + b) / 2
rgb_color_tinted = (avg2(rgb_color[0], rgb_tint[0]),
avg2(rgb_color[1], rgb_tint[1]),
avg2(rgb_color[2], rgb_tint[2]))
return webcolors.rgb_to_hex(rgb_color_tinted)
def open_and_read(filename):
with open(filename) as f:
return f.read()
def tidy_date(date):
"""
Returns the formatted version of the raw Date() class for use in template
"""
return date.strftime("%B %Y")
class PersonalDetail(object):
def __init__(self, label, detail):
self.label = label
self.detail = detail
class Employment(object):
def __init__(self, title, employer, start_date,
description="", finish_date=None):
self.title = title
self.employer = employer
self.start_date = start_date
self.finish_date = finish_date
self.start_date_formatted = tidy_date(self.start_date)
if self.finish_date is not None:
self.finish_date_formatted = tidy_date(self.finish_date)
else:
self.finish_date_formatted = "Current"
self.description = description
self.color = hash_color_tint(
self.title + self.employer, (235, 235, 235))
def get_job_length(self):
if self.finish_date is None:
return (date.today() - self.start_date).days
else:
return (self.finish_date - self.start_date).days
class EmploymentLength(object):
def __init__(self, employment):
self.employment = employment
self.start_date = employment.start_date
self.finish_date = employment.finish_date
self.employment_length = employment.get_job_length()
self.color = employment.color
class YearMarker(object):
def __init__(self, year, percent):
self.year = year
self.percent = percent
def main():
output_filename = "test.html"
template = Template(open_and_read("cv.html"))
details = []
jobs = []
with open("details.json") as j:
json_data = json.load(j)
for k, v in json_data["details"].items():
details.append(PersonalDetail(k, v))
profile = json_data["profile"]['text'].replace('\n', '<br>')
with open("jobs.json") as j:
json_data = json.load(j)
for job in json_data["jobs"]:
finish_date = None
if "finish_date" in job:
finish_date = parse_date(
job["finish_date"], DATE_FORMAT)
jobs.append(Employment(job["title"], job["employer"],
parse_date(job["start_date"], DATE_FORMAT),
job["description"], finish_date))
job_lengths = []
for job in jobs:
job_lengths.append(EmploymentLength(job))
first_day = date.today()
for job_length in job_lengths:
if job_length.start_date < first_day:
first_day = job_length.start_date
total_days = (date.today() - first_day).days
years = []
year_count = int(math.ceil(total_days / 365.25))
for year in range(first_day.year + 1, first_day.year + year_count):
years.append(
YearMarker(year, (date(year, 1, 1) - first_day).days /
float(total_days) * 100))
for job_length in job_lengths:
job_length.employment_length_percent = job_length.employment_length / \
float(total_days) * 100
job_length.start_length_percent = (
job_length.start_date - first_day).days / float(total_days) * 100
with open(output_filename, 'w') as o:
o.write(template.render(details=details, profile=profile,
jobs=jobs, job_lengths=job_lengths, years=years,
projects=["WebUI", "fuckitdb", "Tuara"]))
print("Output saved to {}".format(output_filename))
if __name__ == '__main__':
main()