-
Notifications
You must be signed in to change notification settings - Fork 0
/
writeup-readme.py
72 lines (56 loc) · 2.82 KB
/
writeup-readme.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
import json
import os
from urllib.parse import unquote
from datetime import datetime
def load_data(file_path):
with open(file_path, 'r') as file:
data = json.load(file)
return data
def generate_writeup(data, year):
categories = {}
for challenge in data['data']:
if challenge['solved_by_me']:
category = challenge['category']
if category not in categories:
categories[category] = []
categories[category].append(challenge)
for category, challenges in categories.items():
category_dir = os.path.join(str(year), category.lower().replace(" ", "-"))
os.makedirs(category_dir, exist_ok=True)
for challenge in challenges:
name_decoded = unquote(challenge['name'])
name_lowercase = name_decoded.lower()
name_with_dash = name_lowercase.replace(" ", "-")
challenge_file_path = os.path.join(category_dir, f"{name_with_dash}.md")
solved = "✔" if challenge['solved_by_me'] else "❌"
with open(challenge_file_path, 'w') as f:
f.write(f"---\n")
f.write(f"title: \"{name_decoded}\"\n")
f.write(f"description: \"task\"\n")
f.write(f"points: {challenge['value']}\n")
f.write(f"solves: {challenge['solves']}\n")
f.write(f"author: nobody\n")
f.write(f"---\n\n")
f.write(f"yeh' {name_decoded}.... it was hard lol\n")
with open(os.path.join(category_dir, 'README.md'), 'w') as readme_file:
readme_file.write(f"# {category.capitalize()} Challenges\n\n")
readme_file.write("List of challenges in this category:\n\n")
for challenge in challenges:
name_decoded = unquote(challenge['name'])
name_with_dash = name_decoded.lower().replace(" ", "-")
readme_file.write(f"- {name_decoded} - Solves: {challenge['solves']}\n")
with open(os.path.join(str(year), 'README.md'), 'w') as year_readme_file:
year_readme_file.write("# Challenge Writeup\n\n")
for category, challenges in categories.items():
year_readme_file.write(f"## {category.capitalize()} Challenges\n\n")
for challenge in challenges:
name_decoded = unquote(challenge['name'])
name_with_dash = name_decoded.lower().replace(" ", "-")
year_readme_file.write(f"- **{name_decoded}** ({challenge['value']} points) - Solved: {'✔' if challenge['solved_by_me'] else '❌'} - Solves: {challenge['solves']}\n\n")
def main():
year = datetime.now().year
data = load_data(f"{year}/data.json")
generate_writeup(data, year)
print("Writeup directory structure created successfully.")
if __name__ == "__main__":
main()