Added ability to download images from search.

This commit is contained in:
bafoed
2016-12-17 09:57:58 +03:00
parent e86ec7223b
commit 8e77b9e74f

View File

@@ -15,6 +15,7 @@ import re
import requests import requests
import tqdm import tqdm
import time import time
import urllib
os.makedirs('Wallhaven', exist_ok=True) os.makedirs('Wallhaven', exist_ok=True)
@@ -25,7 +26,7 @@ def login():
req = requests.post('https://alpha.wallhaven.cc/auth/login', data={'username':username, 'password':password}) req = requests.post('https://alpha.wallhaven.cc/auth/login', data={'username':username, 'password':password})
return req.cookies return req.cookies
def choice(): def category():
print('''**************************************************************** print('''****************************************************************
Category Codes Category Codes
@@ -89,18 +90,31 @@ def latest():
latesturl = 'https://alpha.wallhaven.cc/latest?page=' latesturl = 'https://alpha.wallhaven.cc/latest?page='
return (latesturl, dict()) return (latesturl, dict())
def search():
query = input('Enter search query: ')
searchurl = 'https://alpha.wallhaven.cc/search?q=' + \
urllib.parse.quote_plus(query) + '&page='
return (searchurl, dict())
def main(): def main():
Choice = input('''Do you want to choose categories or want to download latest wallpapers: Choice = input('''Choose how you want to download the image:
Enter "yes" for choosing categories
Enter "no" for Downloading latest wallpapers
Enter choice: ''') Enter "category" for downloading wallpapers from specified categories
Enter "latest" for downloading latest wallpapers
Enter "search" for downloading wallpapers from search
if Choice.lower() == 'yes': Enter choice: ''').lower()
BASEURL, cookies = choice() while Choice not in ['category', 'latest', 'search']:
else: if Choice != None:
print('You entered an incorrect value.')
choice = input('Enter choice: ')
if Choice == 'category':
BASEURL, cookies = category()
elif Choice == 'latest':
BASEURL, cookies = latest() BASEURL, cookies = latest()
elif Choice == 'search':
BASEURL, cookies = search()
pgid = int(input('How Many pages you want to Download: ')) pgid = int(input('How Many pages you want to Download: '))
print('Number of Wallpapers to Download: ' + str(24 * pgid)) print('Number of Wallpapers to Download: ' + str(24 * pgid))