Silicaly

DownloadPSMPkgs

Oct 23rd, 2017
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. import re
  2.  
  3. import sys
  4.  
  5. import requests
  6.  
  7. def downloadWithProgressBar(link, file_name):
  8. with open(file_name, "wb") as f:
  9. print "\nDownloading %s" % file_name
  10. response = requests.get(link, stream=True)
  11. total_length = response.headers.get('content-length')
  12.  
  13. if total_length is None: # no content length header
  14. f.write(response.content)
  15. else:
  16. dl = 0
  17. total_length = int(total_length)
  18. for data in response.iter_content(chunk_size=4096):
  19. dl += len(data)
  20. f.write(data)
  21. done = int(50 * dl / total_length)
  22. sys.stdout.write("\r[%s%s]" % ('=' * done, ' ' * (50-done)) )
  23. sys.stdout.flush()
  24.  
  25. file = open("psmpkg.csv")
  26. data = file.read()
  27. urls = re.findall('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', data.replace(",MISSING,",""))
  28.  
  29. count = 0
  30. while count != len(urls):
  31. downloadWithProgressBar(urls[count],str(count)+".pkg")
  32. count += 1
Add Comment
Please, Sign In to add comment