-
-
Save tehmasta/03f67593fcd4b4366dff17e47d586668 to your computer and use it in GitHub Desktop.
Generates a README.md with TryHackMe tasks and questions automatically.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import requests | |
import sys | |
from datetime import datetime | |
import re | |
tag_re = re.compile(r'(<!--.*?-->|<[^>]*>)') | |
name = "" # change this | |
code = "" | |
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): | |
return requests.get(f"https://tryhackme.com/api/tasks/{code}").json()['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)))) # strip HTML tags from the question text | |
f.write(f"{questions}") | |
print("Wrote notes file!") | |
return | |
get_room_code(sys.argv) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment