Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hsc/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .crawler import Crawler
from .crawler import Crawler
4 changes: 4 additions & 0 deletions hsc/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from hsc.crawler import main

if __name__ == "__main__":
main()
21 changes: 12 additions & 9 deletions hsc/crawler.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

class Crawler:
base_url = 'https://www.hackerrank.com/'
user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X x.y; rv:42.0) Gecko/20100101 Firefox/42.0'
login_url = base_url + 'auth/login'
submissions_url = base_url + 'rest/contests/master/submissions/?offset={}&limit={}'
challenge_url = base_url + 'rest/contests/master/challenges/{}/submissions/{}'
Expand Down Expand Up @@ -40,11 +41,13 @@ def __init__(self):
self.options = {}

def login(self, username, password):
resp = self.session.get(self.login_url, auth=(username, password))
self.cookies = self.session.cookies.get_dict()
self.headers = resp.request.headers
self.get_number_of_submissions()
return self.total_submissions != 0
resp = self.session.post(self.login_url, auth=(username, password), headers={'user-agent': self.user_agent})
data = resp.json()
if data['status']:
self.cookies = self.session.cookies.get_dict()
self.headers = resp.request.headers
self.get_number_of_submissions()
return data['status']

def parse_script(self):
p = configargparse.ArgParser(default_config_files=['./user.yaml'])
Expand Down Expand Up @@ -128,7 +131,7 @@ def update_readmes(self, domain_name, subdomain_name, domain_url, subdomain_url,
subdomain_readme_path, domain_readme_path, root_readme_path)

problem_url = self.problem_url.format(challenge_slug)

file_path_relative_to_subdomain = './' + file_name_with_extension
file_path_relative_to_domain = '{}/{}'.format(subdomain_name, file_name_with_extension)
file_path_relative_to_root = '{}/{}/{}'.format(domain_name, subdomain_name, file_name_with_extension)
Expand Down Expand Up @@ -173,7 +176,7 @@ def get_submissions(self, submissions):
data = resp.json()['model']
code = data['code']
track = data['track']

# Default should be empty
file_extension = ''
file_name = challenge_slug
Expand All @@ -189,7 +192,7 @@ def get_submissions(self, submissions):
subdomain_name = track['name'].strip().replace(' ', '')
domain_slug = track['track_slug']
subdomain_slug = track['slug']

domain_url = self.domain_url.format(domain_slug)
subdomain_url = self.subdomain_url.format(domain_slug, subdomain_slug)

Expand All @@ -206,7 +209,7 @@ def get_submissions(self, submissions):
if self.make_language_folder:
file_path = os.path.join(self.base_folder_name, domain_name, subdomain_name, language, file_name_with_extension)
self.store_submission(file_path, code)

self.update_readmes(domain_name, subdomain_name, domain_url, subdomain_url,
challenge_name, challenge_slug, language, file_name_with_extension)

Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name='hsc',
version='1.2.1',
version='1.2.2',
author='Nullifiers',
author_email='nullifiersorg@gmail.com',
description='Hackerrank Solution Crawler',
Expand All @@ -21,7 +21,7 @@
],
entry_points={
'console_scripts': [
'hsc=hsc.crawler:main',
'hsc=hsc.__main__:main',
],
},
install_requires=['progress', 'requests', 'configargparse']
Expand Down