Skip to content

Instantly share code, notes, and snippets.

@xl00t
Created May 12, 2022 15:05
Show Gist options
  • Save xl00t/855d61aaecc2e7c09231361db01d3e6c to your computer and use it in GitHub Desktop.
Save xl00t/855d61aaecc2e7c09231361db01d3e6c to your computer and use it in GitHub Desktop.
root-me.py
import requests
from bs4 import BeautifulSoup
import re
URL = "https://www.root-me.org/"
GRADES = {
"visitor": 100,
"curious": 500,
"trainee": 2017,
"insider": 3535,
"enthusiast": 8207,
"hacker": 13024,
"elite": 18717,
"legend": 20040
}
class RootMe():
def __init__(self, user):
self.user = user
self.soup = self.get_page()
self.place, self.points, self.challenges, self.compromissions = self.get_all()
self.grade = self.get_grade()
def print_data(self):
print(f"Pseudo: {self.user}")
print(f"Place: {self.place}")
print(f"Points: {self.points}")
print(f"Challenges: {self.challenges}")
print(f"Compromissions: {self.compromissions}")
print(f"Grade: {self.grade}")
def get_page(self):
return BeautifulSoup(requests.get(f"{URL}{self.user}").text, "lxml")
def get_all(self):
return [i.split('</h3>')[0] for i in [re.findall("\d*</h3>", repr(div)) for div in self.soup.find_all("div", {"class": "medium-6 columns"})][1]]
def get_grade(self):
for elem in GRADES:
if int(self.points) <= GRADES[elem]:
return elem
if __name__ == '__main__':
rm = RootMe('xl00t')
rm.print_data()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment