Skip to content
Open
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions examdownloader-cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def startDownload(module, username, destination, password):
ed = examdownloader.examdownloader('CLI')

def updateStatus(msg, type='normal'):
print msg
print(msg)

def downloadCallback(status, lastfile='', numFiles=0):
if status:
Expand All @@ -37,7 +37,7 @@ def downloadCallback(status, lastfile='', numFiles=0):
username = args.get("user")
# If not set by user even in the command line arguments
if not username:
username = raw_input('Enter NUSNET ID: ')
username = input('Enter NUSNET ID: ')

# always ask for security reasons
password = getpass.getpass('Enter password for {}: '.format(username))
Expand All @@ -46,7 +46,7 @@ def downloadCallback(status, lastfile='', numFiles=0):
module = args.get("module")
# if not set in CL arguments
if not module:
module = raw_input("Enter module to download exams for: ")
module = input("Enter module to download exams for: ")

# If not set by user in top part of the file
# defaults to "." by configuration of argparse
Expand Down
10 changes: 5 additions & 5 deletions examdownloader-gui.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from Tkinter import *
import tkFileDialog
from tkinter import *
import tkinter.filedialog
import subprocess
import thread
import _thread
import examdownloader

FONT = ('Arial', 14, 'bold')
Expand Down Expand Up @@ -66,7 +66,7 @@ def __init__(self):
root.mainloop()

def askForDestination(self):
self.destination = tkFileDialog.askdirectory(mustexist=False, parent=self.top, title='Choose a destination')
self.destination = tkinter.filedialog.askdirectory(mustexist=False, parent=self.top, title='Choose a destination')
self.destField.delete(0, END)
self.destField.insert(0, self.destination)

Expand All @@ -84,7 +84,7 @@ def downloadCallback(status, lastfile='', numFiles=0):
else:
self.updateStatus('Paper not released by Department', 'error')

thread.start_new_thread(ed.getContents, (module, username, password, destination, downloadCallback, self.updateStatus))
_thread.start_new_thread(ed.getContents, (module, username, password, destination, downloadCallback, self.updateStatus))

def updateStatus(self, msg, type='normal'):
self.statusLabel['text'] = msg
Expand Down
26 changes: 13 additions & 13 deletions examdownloader.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import httplib
import urllib
import http.client
import urllib.request, urllib.parse, urllib.error
import os

class examdownloader(object):
Expand All @@ -9,7 +9,7 @@ def __init__(self, mode):
def getContents(self, module, username, password, destination, downloadEndCallback, updateStatus):
updateStatus('Connecting to NUS Library Portals...')

conn = httplib.HTTPSConnection('libbrs.nus.edu.sg')
conn = http.client.HTTPSConnection('libbrs.nus.edu.sg')
page = '/infogate/loginAction.do?execution=login'
conn.request('GET', page)

Expand All @@ -32,9 +32,9 @@ def getContents(self, module, username, password, destination, downloadEndCallba
'domain': 'NUSSTU',
'key': 'blankid+RESULT+EXAM+' + module
}
params = urllib.urlencode(params)
params = urllib.parse.urlencode(params)

conn = httplib.HTTPSConnection('libbrs.nus.edu.sg')
conn = http.client.HTTPSConnection('libbrs.nus.edu.sg')
conn.request('POST', page, params, headers)
resp = conn.getresponse()
data = str(resp.read())
Expand All @@ -44,12 +44,12 @@ def getContents(self, module, username, password, destination, downloadEndCallba
updateStatus("Wrong username/password", "error")
return

conn = httplib.HTTPSConnection('libbrs.nus.edu.sg')
conn = http.client.HTTPSConnection('libbrs.nus.edu.sg')
page = '/infogate/jsp/login/success.jsp;jsessionid='+sessionid+'?exe=ResultList'
conn.request('GET', page, params, headersGet)
conn.close()

conn = httplib.HTTPSConnection('libbrs.nus.edu.sg')
conn = http.client.HTTPSConnection('libbrs.nus.edu.sg')
page = '/infogate/searchAction.do?execution=ResultList'
params = 'database=EXAM&searchstring='+module+'&d='
conn.request('POST', page, params, headers)
Expand All @@ -68,11 +68,11 @@ def getContents(self, module, username, password, destination, downloadEndCallba
return

for i in range(1, maxDocIndex+1):
conn = httplib.HTTPSConnection('libbrs.nus.edu.sg')
conn = http.client.HTTPSConnection('libbrs.nus.edu.sg')
page = '/infogate/searchAction.do?execution=ViewSelectedResultListLong'
params['preSelectedId'] = i
params['exportids'] = i
conn.request('POST', page, urllib.urlencode(params), headers)
conn.request('POST', page, urllib.parse.urlencode(params), headers)
resp = conn.getresponse()
data = resp.read()
conn.close()
Expand All @@ -95,11 +95,11 @@ def getContents(self, module, username, password, destination, downloadEndCallba
pdfs[title] = page

counter = 0;
for title, page in pdfs.items():
for title, page in list(pdfs.items()):
counter += 1
updateStatus('Downloading ' + str(counter) + ' of ' + str(len(pdfs)))

conn = httplib.HTTPSConnection('libbrs.nus.edu.sg')
conn = http.client.HTTPSConnection('libbrs.nus.edu.sg')
conn.request('GET', page, None, headersGet)
resp = conn.getresponse()
data = resp.read()
Expand All @@ -112,10 +112,10 @@ def getContents(self, module, username, password, destination, downloadEndCallba
os.makedirs(os.path.dirname(filename))
try:
f = open(filename, 'wb')
print('Writing ' + title)
print(('Writing ' + title))
f.write(data)
f.close()
except Exception, e:
except Exception as e:
updateStatus('Invalid destination', 'error')
return

Expand Down