From 1eff3f9e02a007ac865c063b3750e4a4b26be54f Mon Sep 17 00:00:00 2001 From: nx_yan Date: Fri, 26 Nov 2010 07:30:21 +0800 Subject: [PATCH] Added auto zip extractor --- PSDownloaderGUI.py | 50 +++++++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/PSDownloaderGUI.py b/PSDownloaderGUI.py index f798adb..892fa02 100644 --- a/PSDownloaderGUI.py +++ b/PSDownloaderGUI.py @@ -3,8 +3,8 @@ import PythonLeo from Tkinter import * import threading - -URL_LIST = {"current_module":"http://leo.rp.edu.sg/workspace/studentModule.asp?", #to get project_id , group_id +import zipfile,shutil +URL_LIST = {"current_module":"http://leo.rp.edu.sg/workspace/studentModule.asp?site=3", #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/" }; @@ -17,54 +17,64 @@ def download(): 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] response.set("Downloading") os.chdir(os.path.expanduser("~/Desktop")) zip_file = open("problem.zip","wb") zip_file.write( leo.open_url(download_url).read() ) zip_file.close() - + extractDirectory="" + file=open("problem.zip") + +##WillYan + zfile=zipfile.ZipFile(file) + a=zfile.namelist() + zfile.extractall() + b=os.getcwd()+"/"+"Problem"+str(len(project_id_list))+"/" + os.makedirs(b) + count=0 + for i in a: + extractDirectory=os.getcwd()+"/"+str(i) + filename=a[count][(a[count].rfind("/")+1)::] + if(os.path.isdir(extractDirectory)==False): + shutil.copyfile(extractDirectory,(b+"/"+filename)) + count+=1 + os.remove("problem.zip") response.set("Done!") - + def download_thread(dummy=1): threading.Thread(target=download).start() 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("",download_thread) - + response = StringVar() response.set("") - + response_label = Label(main_frame, textvariable=response,fg="red",anchor=W,justify=LEFT) response_label.grid(column=0,row=2) dl_button = Button(main_frame,text="Download",command=download_thread) dl_button.grid(column=2,row=2) - - root.mainloop() - - - - - \ No newline at end of file + root.mainloop() \ No newline at end of file