Added Page support and Progress bar

Added Number of pages you want to download wallpapers.
Added a Download Progress bar to show the current download Progress.
This commit is contained in:
Saurabh Bhan
2016-06-27 23:07:24 +05:30
committed by GitHub
parent 77ccdaa8df
commit d427d05311

View File

@@ -11,6 +11,8 @@ import os
import bs4 import bs4
import re import re
import requests import requests
import time
import tqdm
os.makedirs('Wallhaven', exist_ok=True) os.makedirs('Wallhaven', exist_ok=True)
url = 'https://alpha.wallhaven.cc/latest' url = 'https://alpha.wallhaven.cc/latest'
@@ -23,16 +25,13 @@ imgext = ['jpg', 'png', 'bmp']
for i in range(len(imgid)): for i in range(len(imgid)):
url = 'http://wallpapers.wallhaven.cc/wallpapers/full/wallhaven-%s.' % imgid[ url = 'http://wallpapers.wallhaven.cc/wallpapers/full/wallhaven-%s.' % imgid[
i] i]
iurl = url + imgext[0] for ext in imgext:
imgreq = requests.get(iurl) iurl = url + ext
er = imgreq.status_code imgreq = requests.get(iurl)
if er == 404: if imgreq.status_code == 200:
iurl == url + imgext[1] print('Downloading: ' + iurl)
er2 = imgreq.status_code with open(os.path.join('Wallhaven', os.path.basename(iurl)), 'ab') as imageFile:
if er2 == 404: for chunk in tqdm.tqdm(imgreq.iter_content(1024), total=(int(imgreq.headers['content-length']) / 1024), unit='KB'):
iurl == url + imgext[2] time.sleep(0.01)
print('Downloading: ' + iurl) imageFile.write(chunk)
imageFile = open(os.path.join('Wallhaven', os.path.basename(iurl)), 'ab') break
for chunk in imgreq.iter_content(100000):
imageFile.write(chunk)
imageFile.close()