-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotegen.py
More file actions
executable file
·49 lines (43 loc) · 1.31 KB
/
Copy pathnotegen.py
File metadata and controls
executable file
·49 lines (43 loc) · 1.31 KB
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
#!/usr/bin/python3
import requests
import sys
from datetime import datetime
import re
tag_re = re.compile(r'(<!--.*?-->|<[^>]*>)') # Removes HTML tags from task data
name = "Change this"
code = "" # Room code for TryHackMe room
def get_room_code(s):
if len(s) == 1:
print("USAGE: ./notegen.py [url] [room code]")
return
else:
if s[1].startswith("https://tryhackme.com/room/"):
code = s[1].split('/')[-1]
else:
code = s[1]
write_notes(code)
def get_room_tasks(code):
task_data = requests.get(f"https://tryhackme.com/api/tasks/{code}").json()['data']
return task_data
def parse_task_data(data):
output = []
for task in data:
output.append(f"# Task {task['taskNo']} - {task['taskTitle']}\n")
for x in task["questions"]:
output.append(f"> {x['question']}\n")
output.append("```\n\n```\n")
return output
def date_generator():
x = datetime.now()
return x.strftime("%B %d, %Y")
def get_room_name(code):
return requests.get(f"https://tryhackme.com/api/room/details?codes={code}").json()[code]["title"]
def write_notes(room):
with open('README.md', 'w') as f:
f.write(f"# {get_room_name(room)}\n\n")
f.write(f"{name} | {date_generator()}\n\n")
questions = tag_re.sub("","\n".join(parse_task_data(get_room_tasks(room))))
f.write(f"{questions}")
print("Wrote notes file!")
return
get_room_code(sys.argv)