-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
140 lines (119 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
139
140
import json
import random
import yaml
from collections import namedtuple
from datetime import timedelta
from functools import partial
from itertools import product
from pathlib import Path
import requests
NLJ = partial('\n'.join)
JSDELIVR_DEVICONS = "https://cdn.jsdelivr.net/gh/devicons/devicon@master/icons"
DEVICONS_GITHUB = "https://github.com/devicons/devicon/raw/master/devicon.json"
IMG_ALT = '{{ height={i.height} width={i.width} }}'
Image = namedtuple('Image', 'text image_url height width')
DevIcon = namedtuple('DevIcon', 'name tags svg_url color')
DEVICONS_JSON = {
icon['name']: DevIcon(
icon['name'],
icon['tags'],
f"{JSDELIVR_DEVICONS}/{icon['name']}/{icon['name']}-{icon['versions']['svg'][0]}.svg",
icon['color'],
)
for icon in requests.get(DEVICONS_GITHUB).json()
}
def load_resume(format='yaml', name='resume'):
return {
'yaml': yaml.safe_load,
'json': json.load,
}[format]((Path.cwd() / f'{name}.{format}').read_text())
def devicons_badges(company=None):
skills_by_company = {
job['id']: job['skills'].split()
for job in load_resume()['work']
}
if company is None or company not in skills_by_company:
unique_skills = set()
for all_skills in skills_by_company.values():
unique_skills |= set(all_skills)
skills = list(unique_skills)
else:
skills = skills_by_company[company]
return [
IMG_ALT.format(i=Image(
text=skill,
image_url=DEVICONS_JSON[skill].svg_url,
height='30px',
width='80px',
))
for skill in skills
if skill in DEVICONS_JSON
]
badges = []
for skill in skills:
options = dict(
left_text=skill,
left_title=skill,
right_text='TODO: calc XP',
right_color='white',
)
icon = icons.get(skill)
if icon:
options['logo'] = icon.svg
options['left_color'] = icon.color
badges.append(badge(**options))
return badges
def salutation_permutations():
"""Say 'Hello, my name is' in a bunch of ways"""
hellojis = '👋 🌊 🙋 🖖'.split()
# https://www.babbel.com/en/magazine/how-to-say-hello-in-10-different-languages
hello = """
hi yo oi
sup hey olá hoi hai hej
ciao hiya aweh hola haai molo
heita hello salut ahlan
howzit hoesit dumela halløj goddag
sawubona
""".split()
hello.extend(['whakind eksê', 'hoe lyk it'])
hello = 'hi yo sup hiya hey haai aweh hola molo haai'.split()
# my_names_are = ['my name is', 'my naam is', 'igama lami ngu']
popeyes = ["i'm ", "ek is ", "ngingu", "ke "]
amongst_our_names = "michael michel mikhail mihály mícheál michele michal miguel mihail michiel mikel mihangel mícheál mikkel".split()
# https://smodin.io/translate-one-text-into-multiple-languages
salutation_permutations = list(product(
hellojis, hello, popeyes, amongst_our_names
))
random.shuffle(salutation_permutations)
salutations = [
f'🤓{emoji}{hello}, {my_name_is}{me}'
for emoji, hello, my_name_is, me in salutation_permutations
]
return salutations
TYPED_JS = "https://cdn.jsdelivr.net/npm/[email protected]"
TYPED_TEMPLATE = """
<script src="{js_url}"></script>
<script>
var typed = new Typed('{dom_element}', {options});
</script>
"""
def typed_js(dom_element, things_to_type):
options = json.dumps(dict(
startDelay=3000,
smartDelete=True,
showCursor=False,
typeSpeed=50,
strings=things_to_type,
))
return TYPED_TEMPLATE.format(
js_url=TYPED_JS,
dom_element=dom_element,
options=options
)
def skills_badges(company=None):
return NLJ(devicons_badges(company))
def typed_salutations():
return typed_js('h1', salutation_permutations())
def define_env(env):
env.variables['skills_badges'] = skills_badges
env.variables['typed_salutations'] = typed_salutations