Skip to content

Instantly share code, notes, and snippets.

@Creased
Created June 3, 2020 18:43
Show Gist options
  • Save Creased/ad9291f9b2affc56f4e9a0249fabd41a to your computer and use it in GitHub Desktop.
Save Creased/ad9291f9b2affc56f4e9a0249fabd41a to your computer and use it in GitHub Desktop.
RM scripts
#!/usr/bin/env python3
import requests
import html
creased = 14542
s = requests.Session()
def get_chall_ids():
finished = False
start = 0
chall_ids = set()
while not finished:
data = s.get(f'https://api.www.root-me.org/challenges/?debut_challenges={start}').json()
if len(data) > 2:
start = int(data[2]['href'].split('=')[-1], 10)
elif data[1]['rel'] == 'next':
start = int(data[1]['href'].split('=')[-1], 10)
else:
finished = True
for i in range(len(data[0])):
chall_ids.add(data[0][str(i)]['id_challenge'])
return chall_ids
def get_chall_left(user):
challs = get_chall_ids()
user_info = s.get(f'https://api.www.root-me.org/auteurs/{user}').json()
solved = set(map(lambda x: x['id_challenge'], user_info['validations']))
chall_left = {}
for chall in (challs - solved):
chall_info = s.get(f'https://api.www.root-me.org/challenges/{chall}').json()
if 'rubrique' in chall_info:
chall_left.setdefault(chall_info['rubrique'], []).append(chall_info['titre'])
for chall_cat in chall_left:
print(f' - {chall_cat}')
for chall in chall_left[chall_cat]:
print(f' - {html.unescape(chall)}')
def main():
# API authentication.
creds = {'login': 'REDACTED', 'password': 'REDACTED'}
s.post('https://api.www.root-me.org/login', data=creds)
get_chall_left(creased)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment