-
Notifications
You must be signed in to change notification settings - Fork 1
/
MadSkillzParser.py
80 lines (68 loc) · 3.03 KB
/
MadSkillzParser.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
#!/usr/bin/env python3
import sys
import logging
from openpyxl import Workbook
from openpyxl.styles import Font, Fill
from openpyxl.worksheet.datavalidation import DataValidation
from urllib.request import urlopen
import re
def import_file_from_readify_github(area):
logging.info(f'Getting latest {area}.md...')
response = urlopen(f'https://raw.githubusercontent.com/Readify/madskillz/master/{area}.md')
logging.info(f'Getting latest {area}.md...Done!')
return response
def change_cell_value(row, column, ws, value):
ws.cell(row = row, column = column).value = value
def change_cell_style_header(row, column, ws):
ws.cell(row = row, column = column).font = Font(size = 14, bold = True)
def change_cell_style_role_description(row, column, ws):
ws.cell(row = row, column = column).font = Font(size = 13)
def get_area():
areas = ["DataAndAnalytics", "Development", "Engineering", "InnovationAndDesign", "Managed Services", "ProgramManager"]
msg = " ".join(str(idx + 1) + "." + x for idx,x in enumerate(areas))
selection = input(f"Select Area (1-{len(areas)}) " + msg + ": ")
return areas[int(selection) - 1]
def main():
area = get_area()
filename = 'MadSkillz.xlsx'
role_pattern = '^## .+'
role_description_pattern = '>.+'
behaviour_pattern = '^- .+'
row_number = 0
wb = Workbook()
active_ws = wb.active
data_validation = DataValidation(type="list", formula1='"Cannot Assess,Need Coaching,Maturing,No Brainer,Outstanding"', allow_blank=False)
f = import_file_from_readify_github(area)
logging.info('Parsing...')
for line in f:
line = line.decode('unicode-escape')
row_number += 1
role = re.search(role_pattern, line)
if role:
active_ws = wb.create_sheet(0)
row_number = 1
active_ws.add_data_validation(data_validation)
active_ws.title = line.strip('#')
line = line.strip('#')
change_cell_value(row_number, 1, active_ws, line)
change_cell_style_header(row_number, 1, active_ws)
change_cell_style_header(row_number, 2, active_ws)
change_cell_value(row_number, 2, active_ws, "Rating")
behaviour = re.search(behaviour_pattern, line)
if behaviour:
change_cell_value(row_number, 1, active_ws, line)
rating_cell = active_ws.cell(row = row_number, column = 2)
data_validation.add(rating_cell)
role_description = re.search(role_description_pattern, line)
if role_description:
line = line.strip('>')
change_cell_value(row_number, 1, active_ws, line)
change_cell_style_role_description(row_number, 1, active_ws)
c = active_ws.cell(row = row_number, column = 1)
c.value = line
logging.info('Parsing...Done!')
wb.save(filename)
logging.info('Saved "%s"', filename)
if __name__ == "__main__":
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
main()