Guest User

Untitled

a guest
Jan 18th, 2018
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. import requests
  2. import urllib.request
  3. import getpass
  4. import pyperclip as pc
  5. import os
  6. from bs4 import BeautifulSoup
  7. from time import sleep
  8.  
  9. def printProgressBar (iteration, total, prefix = '', suffix = '', decimals = 1, length = 100, fill = '#'):
  10. percent = ("{0:." + str(decimals) + "f}").format(100 * (iteration / float(total)))
  11. filledLength = int(length * iteration // total)
  12. bar = fill * filledLength + '-' * (length - filledLength)
  13. print('\r%s |%s| %s%% %s' % (prefix, bar, percent, suffix), end = '\r')
  14. if iteration == total:
  15. print()
  16.  
  17. if __name__ == '__main__':
  18. extensions=('.webm','.gif','.jpeg','.jpg','.png')
  19. thumbnails=('s.jpg','s.png','s.jpeg')
  20. url = pc.paste()
  21. response = requests.get(url)
  22. html = str(response.content)
  23. soup = BeautifulSoup(html,"html.parser")
  24. username=getpass.getuser()
  25.  
  26. subject=soup.find('span', class_="subject")
  27. if subject:
  28. subject=('newBatch')
  29. else:
  30. subject=subject.string
  31.  
  32. try:
  33. os.mkdir('/home/'+username+'/'+subject)
  34. except FileExistsError:
  35. os.chdir('/home/'+username+'/'+subject)
  36. os.chdir('/home/'+username+'/'+subject)
  37.  
  38. l=len(soup.find_all('a'))
  39. printProgressBar(0, l, prefix = 'Progress:', suffix = 'Complete', length = 50)
  40. for i,link in enumerate(soup.find_all('a')):
  41. files=link.get('href')
  42. title=str(link.string)
  43. if (files.endswith(extensions) & title.endswith(extensions)) & (not (files.endswith(thumbnails) & title.endswith(thumbnails))):
  44. urllib.request.urlretrieve('http:'+files,title)
  45. sleep(0.1)
  46. printProgressBar(i + 1, l, prefix = 'Progress:', suffix = 'Complete', length = 50)
Add Comment
Please, Sign In to add comment