-
Notifications
You must be signed in to change notification settings - Fork 0
/
hackerrank.py
40 lines (34 loc) · 1.27 KB
/
hackerrank.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env python
import os
import json
import requests
API_URL = "http://api.hackerrank.com/checker/submission.json"
class HackerRankSubmitter(object):
def __init__(self):
self.langs = self.get_langs(force=True)
def get_langs(self, force=False):
print "getting langs"
if force:
r = requests.get("http://api.hackerrank.com/checker/languages.json").text
print "got langs"
self.langs = json.loads(r)
return self.langs
def submit(self, file_content, lang, challenge, test=False):
if test:
test_cases = challenge.sample['test_cases']
else:
test_cases = challenge.official['test_cases']
submission = {
'source': file_content,
'lang': self.get_langs()['languages']['codes'][lang],
'testcases': json.dumps(test_cases),
'api_key': "hackerrank|128303-15|153420c28478f8f01ee8b86c501ce52a156b4555"
}
try:
response = json.loads(requests.post(API_URL, data=submission, timeout=10.0).text)['result']
except requests.exceptions.Timeout:
response = None
challenge.recalculate_leaderboards()
return response
print "importing things"
hackerrank = HackerRankSubmitter()