Skip to content

Commit

Permalink
Seperated PythonLeo class from the script
Browse files Browse the repository at this point in the history
  • Loading branch information
yemyat committed Nov 24, 2010
1 parent b045af1 commit a0c8b21
Show file tree
Hide file tree
Showing 9 changed files with 370 additions and 25 deletions.
Binary file added MacApp/LEO PS Downloader (for year1).zip
Binary file not shown.
2 changes: 1 addition & 1 deletion MacApp/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import sys
from setuptools import setup

mainscript = 'PythonLeoGUI.py'
mainscript = 'PSDownloaderGUI.py'

if sys.platform == 'darwin':
extra_options = dict(
Expand Down
23 changes: 23 additions & 0 deletions PSDownloader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import re
import os
import PythonLeo
if __name__ == "__main__":
URL_LIST = {"current_module":"http://leo.rp.edu.sg/workspace/studentModule.asp?", #to get project_id , group_id
"current_problem":"http://leo3.rp.edu.sg//projectweb/project_menu.asp?", #to get topic_id
"problem_download":"http://leo.rp.edu.sg/projectweb/projectupload/savefolderas.asp?folder=/databank/projectbank/"
};

leo = PythonLeo.PythonLeo("username","password") #e.g. 91224, 12345
project_id_list = leo.parse_id("projectid",leo.open_url(URL_LIST["current_module"]))
group_id_list = leo.parse_id("groupid",leo.open_url(URL_LIST["current_module"]))
topic_id_list = leo.parse_id("topicid",leo.open_url(URL_LIST["current_problem"]+
"projectid="+str(project_id_list[-1])+
"&groupid="+str(group_id_list[-1])))

get_download_url = leo.open_url(URL_LIST["problem_download"]+topic_id_list[-1])

download_url = "http://leo.rp.edu.sg"+ re.search('HREF=\"(.+?zip)',get_download_url.read()).groups()[0]
os.chdir(os.path.expanduser("~/Desktop"))
zip_file = open("problem.zip","wb")
zip_file.write( leo.open_url(download_url).read())
zip_file.close()
56 changes: 56 additions & 0 deletions PSDownloaderGUI.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import re
import os
import PythonLeo
from Tkinter import *

def download(dummy=1):
URL_LIST = {"current_module":"http://leo.rp.edu.sg/workspace/studentModule.asp?", #to get project_id , group_id
"current_problem":"http://leo3.rp.edu.sg//projectweb/project_menu.asp?", #to get topic_id, year2,3=>leo3, year1=>leo1
"problem_download":"http://leo.rp.edu.sg/projectweb/projectupload/savefolderas.asp?folder=/databank/projectbank/"
};

leo = PythonLeo.PythonLeo(username_field.get(),password_field.get()) #e.g. 91224, 12345
project_id_list = leo.parse_id("projectid",leo.open_url(URL_LIST["current_module"]))
group_id_list = leo.parse_id("groupid",leo.open_url(URL_LIST["current_module"]))
topic_id_list = leo.parse_id("topicid",leo.open_url(URL_LIST["current_problem"]+
"projectid="+str(project_id_list[-1])+
"&groupid="+str(group_id_list[-1])))

get_download_url = leo.open_url(URL_LIST["problem_download"]+topic_id_list[-1])

download_url = "http://leo.rp.edu.sg"+ re.search('HREF=\"(.+?zip)',get_download_url.read()).groups()[0]
os.chdir(os.path.expanduser("~/Desktop"))
zip_file = open("problem.zip","wb")
zip_file.write( leo.open_url(download_url).read() )
zip_file.close()

if __name__ == "__main__":
root = Tk()
root.title("LEO PS Downloader")

main_frame = Frame(root,width=200,height=120)
main_frame.grid(column=0,row=0)

username_label = Label(main_frame, text="Username")
username_label.grid(column=0,row=0)

username_field =Entry(main_frame)
username_field.grid(column=1,row=0,columnspan=2)

password_label = Label(main_frame, text="Password")
password_label.grid(column=0,row=1)

password_field =Entry(main_frame,show="*")
password_field.grid(column=1,row=1,columnspan=2)
password_field.bind("<Return>",download)

dl_button = Button(main_frame,text="Download",command=download)
dl_button.grid(column=2,row=2)

root.mainloop()






22 changes: 0 additions & 22 deletions PythonLeo.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from ntlm import HTTPNtlmAuthHandler
from Tkinter import *
import urllib2
import re

Expand All @@ -20,27 +19,6 @@ def open_url(self, url):
def parse_id(self, which_id, from_url):
response_id = re.findall(which_id+"=(.{38})",from_url.read())
return response_id

if __name__ == "__main__":
URL_LIST = {"current_module":"http://leo.rp.edu.sg/workspace/studentModule.asp?", #to get project_id , group_id
"current_problem":"http://leo3.rp.edu.sg//projectweb/project_menu.asp?", #to get topic_id
"problem_download":"http://leo.rp.edu.sg/projectweb/projectupload/savefolderas.asp?folder=/databank/projectbank/"
};

test = PythonLeo("username","password") #e.g. 91224, 12345
project_id_list = test.parse_id("projectid",test.open_url(URL_LIST["current_module"]))
group_id_list = test.parse_id("groupid",test.open_url(URL_LIST["current_module"]))
topic_id_list = test.parse_id("topicid",test.open_url(URL_LIST["current_problem"]+
"projectid="+str(project_id_list[-1])+
"&groupid="+str(group_id_list[-1])))

get_download_url = test.open_url(URL_LIST["problem_download"]+topic_id_list[-1])

download_url = "http://leo.rp.edu.sg"+ re.search('HREF=\"(.+?zip)',get_download_url.read()).groups()[0]

zip_file = open("problem.zip","wb")
zip_file.write( test.open_url(download_url).read())
zip_file.close()



Expand Down
Binary file added PythonLeo.pyc
Binary file not shown.
7 changes: 6 additions & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,10 @@ to be installed. Please feel free to extend this little script as you desire.
This will install the dependency smoothly only if you have Setuptools. For those, who do not have
Setuptools, please download it at http://pypi.python.org/pypi/setuptools

===== NOTE =====
.exe and .app files are created using py2exe and py2app. The latest changes made at the script may not be included in those .exe and .app files. Having said that, MacApp folder and WinApp folder maybe outdated.

- Developed by a bored RP student (http://jeffis.me) . You can ask questions to me at yemyat@gmail.com

- Developed by a group of bored RP students. You can ask questions to us at yemyat@gmail.com and emoosx@gmail.com. We are willing to collaborate with anyone who is willing to contribute to this project.

Follow us on Twitter at @jeffwadsoeva and @emoosx
Loading

0 comments on commit a0c8b21

Please sign in to comment.