Created
September 7, 2011 00:55
-
-
Save luizribeiro/1199454 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python2 | |
import urllib | |
import urllib2 | |
import cookielib | |
import sys | |
import os | |
# Config {{{ | |
LA_LOGIN = "luizribeiro" | |
LA_PASSW = "minhasenha" | |
# }}} | |
def submit_la(login, passwd, pid, code): | |
cj = cookielib.CookieJar() | |
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) | |
print "Logging in...", | |
login_params = urllib.urlencode({ | |
"username": login, | |
"passwd": passwd, | |
"op2": "login", | |
"lang": "english", | |
"force_session": 1, | |
"return": "B:aHR0cDovL2xpdmVhcmNoaXZlLm9ubGluZWp1ZGdlLm9yZy9pbmRleC5waHA/b3B0aW9uPWNvbV9jb21wcm9maWxlcg==", | |
"message": 0, | |
"loginfrom": "loginmodule", | |
"cbsecuritym3": "cbm_7eba1261_793448d1_84ec8e96dad5e3b30956290992c09e14", | |
"j61e9da49603c0fca0b214d7e89df0902": 1, | |
"remember": "yes" | |
}) | |
resp = opener.open("http://livearchive.onlinejudge.org/index.php?option=com_comprofiler&task=login", login_params) | |
if ("%s Profile Page" % login) not in resp.read(): | |
print "FAIL" | |
return | |
print "DONE" | |
print "Submitting...", | |
submit_params = urllib.urlencode({ | |
"problemid": "", | |
"category": "", | |
"localid": pid, | |
"language": 3, | |
"code": code, | |
}) | |
resp = opener.open("http://livearchive.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=25&page=save_submission", submit_params) | |
if "The selected problem ID does not exist." in resp.read(): | |
print "FAIL" | |
print "Error: The selected problem ID '%s' does not exist." % pid | |
return | |
print "DONE" | |
print resp.read() | |
if __name__ == "__main__": | |
if len(sys.argv) < 2 or len(sys.argv) > 3: | |
sys.exit("Usage: submit <file> [pid]") | |
else: | |
fn = sys.argv[1] | |
if len(sys.argv) == 3: | |
pid = sys.argv[2] | |
else: | |
pid = os.path.splitext(os.path.basename(fn))[0] | |
try: | |
fp = open(fn, 'r') | |
code = fp.read() | |
fp.close() | |
submit_la(LA_LOGIN, LA_PASSW, pid, code) | |
except IOError: | |
sys.exit("Error: could not open file %s" % fn) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment