daily pastebin goal
36%
SHARE
TWEET

cfSubmit

igorjan94 Nov 21st, 2014 (edited) 338 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python3
  2.  
  3. import os
  4. import requests
  5. import sys
  6. import itertools
  7. import time
  8.  
  9. # Edit these four variables according to your needs:
  10. x_user          =  "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
  11. csrf_token      =  "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
  12. cf_domain       =  "ru" #"com" if you prefer codeforces.com
  13. username        =  "igorjan94"
  14. updateInterval  =  2 #in seconds
  15. countOfSubmits  =  1 #count of previous submits, shown after done submission. If count == 1, nothing happens.
  16. ext_id          =  {
  17.     "cpp":   "16",
  18.     "hs":    "12",
  19.     "java":  "36",
  20.     "py":    "31",
  21. }
  22.  
  23. # programTypeId - Language
  24. # 10 - GNU C 4
  25. # 1  - GNU C++ 4.7
  26. # 16 - GNU C++0x 4
  27. # 2  - Microsoft Visual C++ 2010
  28. # 9  - C# Mono 2.10
  29. # 29 - MS C# .NET 4
  30. # 28 - D DMD32 Compiler v2
  31. # 32 - Go 1.2
  32. # 12 - Haskell GHC 7.6
  33. # 5  - Java 6
  34. # 23 - Java 7
  35. # 36 - Java 8
  36. # 19 - OCaml 4
  37. # 3  - Delphi 7
  38. # 4  - Free Pascal 2
  39. # 13 - Perl 5.12
  40. # 6  - PHP 5.3
  41. # 7  - Python 2.7
  42. # 31 - Python 3.3
  43. # 8  - Ruby 2
  44. # 20 - Scala 2.11
  45. # 34 - JavaScript V8 3
  46.  
  47. if len(sys.argv) < 2:
  48.     print("Solution filename not specified")
  49.     sys.exit()
  50.  
  51. if not os.path.exists(sys.argv[1]):
  52.     print("Solution file does not exist or not enough rights to read it")
  53.     sys.exit()
  54.  
  55. filename = os.path.basename(sys.argv[1])
  56.  
  57. contest_id = ''.join(itertools.takewhile(lambda c: c.isdigit(), filename))
  58. problem_index = ''.join(itertools.takewhile(lambda c: c != '.', filename[len(contest_id):])).upper()
  59. extension = filename[len(contest_id) + len(problem_index) + 1:].lower()
  60.  
  61. if (len(contest_id) == 0) or (len(problem_index) == 0):
  62.     contest_id = os.path.dirname(os.path.realpath(sys.argv[1])).split(os.sep)[-1]
  63.     temp = filename.split('.')
  64.     problem_index = temp[0].upper()
  65.     extension = temp[-1].lower()
  66.     if (not contest_id.isdigit() or (len(problem_index) > 2)):
  67.         print("Incorrect filename format. Example: 123A.cpp or 123/A.cpp")
  68.         sys.exit()
  69.  
  70. if not extension in ext_id:
  71.     print("Unknown extension. Please check 'ext_id' variable")
  72.     sys.exit()
  73.  
  74.  
  75. parts = {
  76.         "csrf_token":            csrf_token,
  77.         "action":                "submitSolutionFormSubmitted",
  78.         "submittedProblemIndex": problem_index,
  79.         "source":                open(sys.argv[1], "rb"),
  80.         "programTypeId":         ext_id[extension],
  81.         "sourceFile":            "",
  82.         "_tta":                  "222"
  83. }
  84.  
  85. requests.post("http://codeforces." + cf_domain + "/contest/" + contest_id + "/problem/" + problem_index,
  86.               params = {"csrf_token": csrf_token},
  87.               files = parts,
  88.               cookies = {"X-User": x_user})
  89.  
  90. print("Solution is successfully sent. Current time is " + time.strftime("%H:%M:%S"))
  91.  
  92. while True:
  93.     try:
  94.         data = requests.get("http://codeforces.ru/api/user.status?handle=" + username + "&from=1&count=" + str(countOfSubmits)).json()['result']
  95.     except:
  96.         sleep(updateInterval)
  97.         continue
  98.     if countOfSubmits > 1:
  99.         print("last submits")
  100.         for s in reversed(data[1:]):
  101.             print(str(s['problem']['contestId']) + s['problem']['index'] + " " + \
  102.                     '{:>20}'.format(s['verdict'] + "(" + str(s['passedTestCount'] + 1) + ") ") + str(s['timeConsumedMillis']) + " ms")
  103.         sys.stdout.flush()
  104.     s = data[0]
  105.     print(str(s['problem']['contestId']) + s['problem']['index'] + " " + \
  106.             '{:>20}'.format(s['verdict'] + "(" + str(s['passedTestCount'] + 1) + ") ") + str(s['timeConsumedMillis']) + " ms")
  107.     if s['verdict'] != 'TESTING':
  108.         break
  109.     sleep(updateInterval)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top