Commits

Matthias Jacob committed bb1e17c

split up into download, extract, merge actions

  • Participants
  • Parent commits d42e79c

Comments (0)

Files changed (1)

     print response.info()  # headers
     print response.read()  # body 
 
-def download_and_extract():
+def download(to_filename):
     br = mechanize.Browser()
     response1 = br.open(START_URL)
     
     # download DZE.zip
     #
     
-    f = open(OUTPUT_FILENAME, 'wb')
+    f = open(to_filename, 'wb')
     meta = response7.info()
     file_size = int(meta.getheaders("Content-Length")[0])
-    print "Downloading: %s Bytes: %s" % (OUTPUT_FILENAME, file_size)
+    print "Downloading: %s Bytes: %s" % (to_filename, file_size)
     
     file_size_dl = 0
     block_sz = 512 * 1024
         print status
     
     f.close()
-    
+
+def extract(from_file, to_folder):    
     #
     # unzip
     #
-    zip = zipfile.ZipFile(OUTPUT_FILENAME)
-    zip.extractall(OUTPUT_FOLDER)
-    
+    zip = zipfile.ZipFile(from_file)
+    zip.extractall(to_folder)
+
+def merge_to_pdf(folder):
     #
     # merge PDF
     #
     mergeWriter = PdfFileWriter()
     
-    dirList=os.listdir(OUTPUT_FOLDER)
+    dirList=os.listdir(folder)
     for fname in dirList:
         print fname
         input1 = PdfFileReader(file("DZE/" + fname, "rb"))
     outputStream.close()
 
 if __name__ == '__main__':
-    download_and_extract()
+    download(OUTPUT_FILENAME)
+    extract(OUTPUT_FILENAME, OUTPUT_FOLDER)
+    merge_to_pdf(OUTPUT_FOLDER)