########################################################
#        Program to Download Wallpapers from           #
#                  alpha.wallhaven.cc                  #
#                                                      #
#                 Author - Saurabh Bhan                #
#                                                      #
#                  dated- 26 June 2016                 #
########################################################

import os
import bs4
import re
import requests
import time
import tqdm

os.makedirs('Wallhaven', exist_ok=True)
url = 'https://alpha.wallhaven.cc/latest'
urlreq = requests.get(url)
soup = bs4.BeautifulSoup(urlreq.text, 'lxml')
soupid = soup.findAll('a', {'class': 'preview'})
res = re.compile(r'\d+')
imgid = res.findall(str(soupid))
print('Number of Wallpapers to Download: ' + str(len(imgid)))
imgext = ['jpg', 'png', 'bmp']
for i in range(len(imgid)):
    url = 'http://wallpapers.wallhaven.cc/wallpapers/full/wallhaven-%s.' % imgid[
        i]
        for ext in imgext:
            iurl = url + ext
            imgreq = requests.get(iurl)
            if imgreq.status_code == 200:
                print('Downloading: ' + iurl)
                with open(os.path.join('Wallhaven', os.path.basename(iurl)), 'ab') as imageFile:
                    for chunk in tqdm.tqdm(imgreq.iter_content(1024), total=(int(imgreq.headers['content-length']) / 1024), unit='KB'):
                        time.sleep(0.01)
                        imageFile.write(chunk)
            break

@@ -450,16 +450,39 @@
 ######%0A%0A
+#!usr/bin/env python3%0A%0A
 import o
@@ -585,16 +585,169 @@
 k=True)%0A
+pgid = int(input('How Many pages you want to Download: '))%0Aprint('Number of Wallpapers to Download: ' + str(24 * pgid))%0Afor i in range(1, pgid + 1):%0A    
 url = 'h
@@ -782,10 +782,29 @@
 test
-'%0A
+?page=' + str(i)%0A    
 urlr
@@ -826,16 +826,20 @@
 et(url)%0A
+    
 soup = b
@@ -876,16 +876,20 @@
 'lxml')%0A
+    
 soupid =
@@ -929,16 +929,20 @@
 view'%7D)%0A
+    
 res = re
@@ -958,16 +958,20 @@
 r'%5Cd+')%0A
+    
 imgid = 
@@ -999,70 +999,12 @@
 d))%0A
-print('Number of Wallpapers to Download: ' + str(len(imgid)))%0A
+    
 imge
@@ -1030,16 +1030,20 @@
  'bmp'%5D%0A
+    
 for i in
@@ -1062,16 +1062,20 @@
 mgid)):%0A
+    
     url 
@@ -1148,16 +1148,20 @@
  imgid%5B%0A
+    
         

clean up