Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import urllib.request
- import getpass
- import pyperclip as pc
- import os
- from bs4 import BeautifulSoup
- from time import sleep
- def printProgressBar (iteration, total, prefix = '', suffix = '', decimals = 1, length = 100, fill = '#'):
- percent = ("{0:." + str(decimals) + "f}").format(100 * (iteration / float(total)))
- filledLength = int(length * iteration // total)
- bar = fill * filledLength + '-' * (length - filledLength)
- print('\r%s |%s| %s%% %s' % (prefix, bar, percent, suffix), end = '\r')
- if iteration == total:
- print()
- if __name__ == '__main__':
- extensions=('.webm','.gif','.jpeg','.jpg','.png')
- thumbnails=('s.jpg','s.png','s.jpeg')
- url = pc.paste()
- response = requests.get(url)
- html = str(response.content)
- soup = BeautifulSoup(html,"html.parser")
- username=getpass.getuser()
- subject=soup.find('span', class_="subject")
- if subject:
- subject=('newBatch')
- else:
- subject=subject.string
- try:
- os.mkdir('/home/'+username+'/'+subject)
- except FileExistsError:
- os.chdir('/home/'+username+'/'+subject)
- os.chdir('/home/'+username+'/'+subject)
- l=len(soup.find_all('a'))
- printProgressBar(0, l, prefix = 'Progress:', suffix = 'Complete', length = 50)
- for i,link in enumerate(soup.find_all('a')):
- files=link.get('href')
- title=str(link.string)
- if (files.endswith(extensions) & title.endswith(extensions)) & (not (files.endswith(thumbnails) & title.endswith(thumbnails))):
- urllib.request.urlretrieve('http:'+files,title)
- sleep(0.1)
- printProgressBar(i + 1, l, prefix = 'Progress:', suffix = 'Complete', length = 50)
Add Comment
Please, Sign In to add comment