juan-canham-resume/transform.py
2020-03-17 03:54:15 +00:00

64 lines
1.7 KiB
Python
Executable File

#!/usr/bin/env python
"""
This script transforms a resume from a format container positions within an
employer, to valid FRESH resume format
"""
import os
import json
import copy
import yaml
# pylint: disable=missing-function-docstring
def main():
with open("resume.yaml") as file:
resume = yaml.load(file, Loader=yaml.BaseLoader)
transform_and_write("full", make_full, resume)
transform_and_write("resume", make_fresh, resume)
def write_file(name, data):
filename = os.path.join("dist", name + ".json")
with open(filename, "w") as file:
json.dump(data, file)
def transform_and_write(name, func, raw_data):
data = copy.deepcopy(raw_data)
data = func(data)
write_file(name, data)
def make_fresh(data):
data["skills"].setdefault("list", [])
for skillset in data["skills"]["sets"]:
skills = skillset["skills"][:]
skillset["skills"] = [skill["name"] for skill in skills]
data["skills"]["list"] += skills
return data
def make_full(data):
with open("settings.yaml") as file:
data["settings"] = yaml.load(file, Loader=yaml.BaseLoader)
tags = data.get("tags", [])
for employer in data["employment"]["history"]:
tags += employer.get("technologies", [])
tags += employer.get("keywords", [])
for project in employer.get("projects", []):
tags += project.get("technologies", [])
tags += project.get("keywords", [])
tags = sorted(tags, key=tags.count, reverse=True)
data["tags"] = []
for tag in tags:
if tag not in data["tags"]:
data["tags"].append(tag)
return data
if __name__ == "__main__":
main()