From 673793f76a7b225bd0e77d11055c63107b42aa2f Mon Sep 17 00:00:00 2001 From: "DuyTan.Pham (Stanley00)" Date: Mon, 27 Apr 2015 20:19:59 +0700 Subject: [PATCH 1/4] Explicit select python version --- spojbackup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spojbackup.py b/spojbackup.py index f8e9ae4..8c57598 100644 --- a/spojbackup.py +++ b/spojbackup.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python2 # -*- coding: utf-8 -*- ''' From af54ac0337659ea63ae4a6fdf50434f1e559992d Mon Sep 17 00:00:00 2001 From: "DuyTan.Pham (Stanley00)" Date: Mon, 27 Apr 2015 20:22:58 +0700 Subject: [PATCH 2/4] Change SPOJ domain from spoj.pl to spoj.com --- spojbackup.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spojbackup.py b/spojbackup.py index 8c57598..c3abeb3 100644 --- a/spojbackup.py +++ b/spojbackup.py @@ -74,14 +74,14 @@ def getSolutions (path_prefix, path_proxy): # authenticate the user print "Authenticating " + username - br.open ("http://spoj.pl") + br.open ("http://spoj.com") br.select_form (name="login") 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() @@ -91,7 +91,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): @@ -135,7 +135,7 @@ def downloadSolutions(mysublist): 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 = "" From 733100aba6aeb5b7fe655cfc8a7b4567f04df919 Mon Sep 17 00:00:00 2001 From: "DuyTan.Pham (Stanley00)" Date: Mon, 27 Apr 2015 20:26:38 +0700 Subject: [PATCH 3/4] Change filename to save Using code-status-id.ext --- spojbackup.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/spojbackup.py b/spojbackup.py index c3abeb3..835c49b 100644 --- a/spojbackup.py +++ b/spojbackup.py @@ -121,6 +121,14 @@ 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) @@ -128,8 +136,8 @@ def downloadSolutions(mysublist): 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: @@ -138,12 +146,8 @@ def downloadSolutions(mysublist): 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()) From 1adb92ed3367e4c65b1b7f95bbfbb96b44ac9575 Mon Sep 17 00:00:00 2001 From: "DuyTan.Pham (Stanley00)" Date: Mon, 27 Apr 2015 20:29:51 +0700 Subject: [PATCH 4/4] Handle new interface of SPOJ --- spojbackup.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/spojbackup.py b/spojbackup.py index 835c49b..d85054f 100644 --- a/spojbackup.py +++ b/spojbackup.py @@ -75,7 +75,10 @@ def getSolutions (path_prefix, path_proxy): # authenticate the user print "Authenticating " + username br.open ("http://spoj.com") - br.select_form (name="login") + for form in br.forms(): + if form.attrs['id'] == 'login-form': + br.form = form + break br["login_user"] = username br["password"] = password