Skip to content

Handle interface change of SPOJ #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions spojbackup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python2
# -*- coding: utf-8 -*-

'''
Expand Down Expand Up @@ -74,14 +74,17 @@ def getSolutions (path_prefix, path_proxy):

# authenticate the user
print "Authenticating " + username
br.open ("http://spoj.pl")
br.select_form (name="login")
br.open ("http://spoj.com")
for form in br.forms():
if form.attrs['id'] == 'login-form':
br.form = form
break
br["login_user"] = username
br["password"] = password

# sign in for a day to avoid timeouts
br.find_control(name="autologin").items[0].selected = True
br.form.action = "http://www.spoj.pl"
br.form.action = "http://www.spoj.com"
response = br.submit()

verify = response.read()
Expand All @@ -91,7 +94,7 @@ def getSolutions (path_prefix, path_proxy):

# grab the signed submissions list
print "Grabbing siglist for " + username
siglist = br.open("http://www.spoj.pl/status/" + username + "/signedlist")
siglist = br.open("http://www.spoj.com/status/" + username + "/signedlist")

# dump first nine useless lines in signed list for formatting
for i in xrange(9):
Expand Down Expand Up @@ -121,29 +124,33 @@ def getSolutions (path_prefix, path_proxy):
print "Done !!!"
return mysublist

def getExt(ext):
X={"C99":"c", "C":"c", "C++":"cpp", "PYT":"py", "BAS":"sh", "AWK":"awk", "ASM":"asm", "BF":"bf", "TEX":"txt", "PAS":"pas"}
try:
return X[ext]
except:
return ext


def downloadSolutions(mysublist):
totalsubmissions = len(mysublist)

print "Fetching sources into " + path_prefix
progress = 0

for entry in mysublist:
existing_files = glob.glob(os.path.join(path_prefix, "%s-%s*" % \
(entry[3],entry[1])))
existing_files = glob.glob(os.path.join(path_prefix, "%s-%s-%s*" % \
(entry[3],entry[4], entry[1])))

progress += 1
if len(existing_files) == 1:
print "%d/%d - %s skipped." % (progress, totalsubmissions, entry[3])
else:
source_code = br.open("http://www.spoj.pl/files/src/save/" + \
source_code = br.open("http://www.spoj.com/files/src/save/" + \
entry[1])
header = dict(source_code.info())
filename = ""
try:
filename = header['content-disposition'].split('=')[1]
filename = entry[3] + "-" + filename
except:
filename = entry[3] + "-" + entry[1]
filename = "-".join([entry[3],entry[4], entry[1]])
filename = filename + "." + getExt(entry[7])

fp = open( os.path.join(path_prefix, filename), "w")
fp.write (source_code.read())
Expand Down