Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- import os
- import requests
- import sys
- import itertools
- import time
- judge_id = "XXXXXXXX"
- ext_id = {
- "cpp" : "10",
- "c" : "9",
- "py" : "35",
- "java" : "32",
- }
- """
- Timus Online Judge compilators' ids:
- "31" > FreePascal 2.6
- "9" > Visual C 2010
- "10" > Visual C++ 2010
- "25" > GCC 4.9
- "26" > G++ 4.9
- "27" > GCC 4.9 C11
- "28" > G++ 4.9 C++11
- "30" > Clang 3.5 C++14
- "32" > Java 1.8
- "11" > Visual C# 2010
- "15" > VB.NET 2010
- "34" > Python 2.7
- "35" > Python 3.4
- "14" > Go 1.3
- "18" > Ruby 1.9
- "19" > Haskell 7.6
- "33" > Scala 2.11
- """
- if len(sys.argv) < 2:
- print("Solution filename not specified")
- sys.exit()
- if not os.path.exists(sys.argv[1]):
- print("Solution file does not exist or not enough rights to read it")
- sys.exit()
- filename = os.path.basename(sys.argv[1])
- problem_index = ''.join(itertools.takewhile(lambda c: c.isdigit(), filename));
- extension = filename[len(problem_index) + 1:].lower()
- if (len(problem_index) == 0):
- print("Incorrect filename format. Example: 1000.cpp")
- sys.exit()
- if extension not in ext_id:
- print("Unknown extension. Please check 'ext_id' variable")
- sys.exit()
- data = {
- "Action": "submit",
- "JudgeID": judge_id,
- "ProblemNum": problem_index,
- "Source": open(sys.argv[1], "rb").read(),
- "Language": ext_id[extension],
- "SourceFile": "",
- "SpaceID": "1"
- }
- submit_addr = "http://acm.timus.ru/submit.aspx"
- requests.post(submit_addr, data=data)
- print ("\n Solution is successfully sent. Current time is " + time.strftime("%H:%M:%S") + "\n")
- status_addr = "http://acm.timus.ru/status.aspx"
- author_id = ''.join(itertools.takewhile(lambda c: c.isdigit(), judge_id))
- old_verdict = " "
- while True:
- req = requests.get(status_addr, params={ "author" : author_id })
- con = req.text
- id0 = con.find("Memory used")
- id1 = con.find("nofollow", id0)
- id2 = con.find("<", id1)
- submit_id = con[id1+10:id2]
- id1 = con.find("verdict", id2)
- id2 = con.find("<", id1)
- new_verdict = con[id1+12:id2]
- br = new_verdict.find("(")
- if (br != -1):
- new_verdict = new_verdict[:br-1]
- id1 = con.find("test", id2)
- id2 = con.find("<", id1)
- test = con[id1+6:id2]
- id1 = con.find("runtime", id2)
- id2 = con.find("<", id1)
- runtime = con[id1+9:id2]
- id1 = con.find("memory", id2)
- id2 = con.find("<", id1)
- memory = con[id1+8:id2]
- if (old_verdict != new_verdict):
- if (new_verdict == "Compiling" or new_verdict == "Running"):
- print (" " + new_verdict + "...")
- else:
- print("--------------------------------------------------------------------")
- if (new_verdict == ""):
- print ('%22s' % ("Compilation error"), "\t\tTime: 0", "\tMemory used: 0 KB", '\n')
- ses = requests.Session()
- ses.post("http://acm.timus.ru/auth.aspx", data = { "JudgeID" : judge_id, "Action" : "login" } )
- print(ses.get("http://acm.timus.ru/ce.aspx?id=" + submit_id).text)
- elif (new_verdict == "Accepted"):
- print ('%22s' % (new_verdict), "\t\tTime: ", runtime, "\tMemory used: ", memory, "\n")
- else:
- print ('%22s' % (new_verdict), "\t", test, "\tTime: ", runtime, "\tMemory used: ", memory, "\n")
- break
- old_verdict = new_verdict
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement