Last active
May 8, 2024 10:02
-
-
Save rbpi/4d124b293ff7506090714c22ca8da473 to your computer and use it in GitHub Desktop.
HTB Academy Certificate Exams Results Monitoring
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
# HTB Academy Certificate Exams Results Monitoring | |
# Author: RBPi | |
import requests | |
import time | |
import random | |
import os | |
import urllib.parse | |
import urllib.request | |
HTB_EXAM = 'CBBH' # 'CBBH' or 'CDSA' | |
HTB_COOKIE_VALUE = '' # Replace with your own Cookie value | |
BROWSER_UA = '' # Replace with your browser User-Agent value | |
# ServerChan (SendKey): echo 'SENDKEY=XXXXXXXXXXXX' > .env | |
def send_get_request(): | |
if HTB_EXAM == 'CBBH': | |
exam_id = 2 | |
elif HTB_EXAM == 'CDSA': | |
exam_id = 4 | |
else: | |
print("Invalid exam type. Please redefine the exam as 'CBBH' or 'CDSA'.") | |
return | |
url = f'https://academy.hackthebox.com/api/v2/exams/{exam_id}/attempts' | |
headers = { | |
'User-Agent': BROWSER_UA, | |
'Cookie': HTB_COOKIE_VALUE, | |
'Referer': f'https://academy.hackthebox.com/exams/{exam_id}/' | |
} | |
attempts = 0 | |
while attempts < 3: | |
try: | |
response = requests.get(url, headers=headers) | |
response.raise_for_status() | |
data = response.json() | |
status = data['data'][0]['status'] | |
if status == 'In Review': | |
wait_time = random.randint(300, 600) # Random wait time between 5 to 10 minutes | |
print(f"Status is 'In Review'. Waiting {wait_time} seconds before sending the request again...") | |
time.sleep(wait_time) | |
elif status in ['Failed', 'Certified']: | |
if 'review' in data['data'][0]: | |
review_data = data['data'][0]['review'] | |
feedback = review_data['feedback'] | |
ret = sc_send(status, f'{feedback}\n\n第二行', key) | |
print(ret) | |
break | |
else: | |
print("Invalid status received.") | |
break | |
except requests.exceptions.RequestException as e: | |
print(f"An error occurred: {e}") | |
print("Response content:", response.content) | |
attempts += 1 | |
print(f"Retrying in 60 seconds... (Attempt {attempts})") | |
time.sleep(60) # Wait for 60 seconds | |
if attempts == 3: | |
print("Request error exceeded 3 attempts. Exiting the script.") | |
data = {} | |
with open(os.path.join(os.path.dirname(__file__), '..', '.env'), 'r') as f: | |
for line in f: | |
key, value = line.strip().split('=') | |
data[key] = value | |
key = data['SENDKEY'] | |
def sc_send(text, desp='', key='[SENDKEY]'): | |
postdata = urllib.parse.urlencode({'text': text, 'desp': desp}).encode('utf-8') | |
url = f'https://sctapi.ftqq.com/{key}.send' | |
req = urllib.request.Request(url, data=postdata, method='POST') | |
with urllib.request.urlopen(req) as response: | |
result = response.read().decode('utf-8') | |
return result | |
send_get_request() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I enjoy the certification from HTB Academy. It is affordable and provides a wealth of fundamental knowledge in information security.
Once you take the exam, you'll be eager to know your results.
Don't hesitate to use this script!