Advertisement
Guest User

The Huxley Toolkit

a guest
Oct 14th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.47 KB | None | 0 0
  1. import getpass
  2. import json
  3. import os
  4. import requests
  5.  
  6. print('The Huxley Toolkit')
  7.  
  8. s = requests.session()
  9. data = {
  10.     "username": raw_input("The Huxley username: "),
  11.     "password": getpass.getpass("The Huxley password: "),
  12.     "grant_type": "password",
  13.     "scope": "read",
  14.     "client_id": "ui",
  15.     "Name": None
  16. }
  17. headers = {
  18.     "Authorization": "Basic dWk6"
  19. }
  20. headers = {
  21.     "Authorization": "Bearer %s" % json.loads(s.post('https://www.thehuxley.com/auth/oauth/token', headers=headers, data=data).content)['access_token']
  22. }
  23.  
  24. while True:
  25.     print
  26.     print('1 - Get problems of list')
  27.     print('2 - Get source code')
  28.     print('3 - Get input and output of problem')
  29.     print('0 - Exit')
  30.     i = input('Select an option above: ')
  31.     print
  32.  
  33.     if i == 0:
  34.         break
  35.  
  36.     elif i == 1:
  37.         list_id = input('The Huxley list id: ')
  38.         r = s.get('https://www.thehuxley.com/api/v1/user/quizzes/%s/problems?max=100&offset=0' % list_id, headers=headers)
  39.         j = json.loads(r.content)
  40.  
  41.         print
  42.         print('List %s' % list_id)
  43.         for e in j:
  44.             print('https://www.thehuxley.com/problem/%s' % e['id'])
  45.  
  46.     elif i == 2:
  47.         submission_id = input('The Huxley submission id: ')
  48.         r = s.get('https://www.thehuxley.com/api/v1/submissions/%s/sourcecode' % submission_id, headers=headers)
  49.  
  50.         sourcecode_path = os.path.join(os.path.expanduser('~'), 'Desktop', '%s-sourcecode.txt' % submission_id)
  51.         f = open(sourcecode_path, 'wb')
  52.         f.write(r.content)
  53.         f.close()
  54.  
  55.         print
  56.         print('Source code saved at %s' % sourcecode_path)
  57.  
  58.     elif i == 3:
  59.         problem_id = input('The Huxley problem id: ')
  60.         testcase_id = input('The Huxley test case id: ')
  61.         r = s.get('https://www.thehuxley.com/api/v1/problems/%s/testcases/%s' % (problem_id, testcase_id), headers=headers)
  62.         j = json.loads(r.content)
  63.  
  64.         input_path = os.path.join(os.path.expanduser('~'), 'Desktop', '%s-%s-input.txt' % (problem_id, testcase_id))
  65.         f = open(input_path, 'wb')
  66.         f.write(j['input'])
  67.         f.close()
  68.  
  69.         output_path = os.path.join(os.path.expanduser('~'), 'Desktop', '%s-%s-output.txt' % (problem_id, testcase_id))
  70.         f = open(output_path, 'wb')
  71.         f.write(j['output'])
  72.         f.close()
  73.  
  74.         print
  75.         print('Input saved at %s' % input_path)
  76.         print('Output saved at %s' % output_path)
  77.  
  78.     else:
  79.         print('Invalid option!')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement