Skip to content

Instantly share code, notes, and snippets.

@saga
Forked from thefinn93/wallbase.py
Created May 30, 2014 04:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saga/b1022dbfa76f8c31bf80 to your computer and use it in GitHub Desktop.
Save saga/b1022dbfa76f8c31bf80 to your computer and use it in GitHub Desktop.
#! /usr/bin/env python
import sys
import json
import subprocess
import urllib
try:
import requests
except:
print "Install requests (try easy_install requests)"
sys.exit()
try:
from BeautifulSoup import BeautifulSoup
except:
print "Install BeautifulSoup (try easy_install beautifulsoup)"
sys.exit()
try:
from termcolor import colored, cprint
except:
print "Install termcolor (try easy_install termcolor)"
sys.exit()
username="" # Remember to clear this
password="" # before sharing :D
login = requests.post("http://wallbase.cc/user/login","username="+username+"&pass="+password+"&nopass_email=Type+in+your+e-mail+and+press+enter&nopass=0")
q = ""
if len(sys.argv) == 1:
q = raw_input("What would you like to search for? ")
else:
q = " ".join(sys.argv[1:])
cprint("For the following options, simply press enter for all","yellow")
res = raw_input("Specify resolution (WIDTHxHEIGHT): ")
if res == "":
res = "0x0"
aspect = raw_input("Specify aspect ratio (width:height): ")
if aspect == "":
aspcet = "0"
cprint("Searching for " + q, "grey")
page = 0
a = json.loads(requests.post("http://wallbase.cc/search/"+str(page),"query="+q+"&board=12&res_opt=eqeq&res=" + res + "&aspect=" + aspect + "&nsfw_sfw=1&nsfw_sketchy=1&nsfw_nsfw=1&thpp=60&orderby=reference&orderby_opt=desc",cookies=login.cookies,headers={"X-Requested-With":"XMLHttpRequest","User-Agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.30 Safari/536.5"}).content)
while len(a) > 1:
cprint("Loading 32 images starting at " + str(page), "yellow")
a = json.loads(requests.post("http://wallbase.cc/search/"+str(page),"query="+q+"&board=12&res_opt=eqeq&res=" + res + "&aspect=" + aspect + "&nsfw_sfw=1&nsfw_sketchy=1&nsfw_nsfw=1&thpp=60&orderby=reference&orderby_opt=desc",cookies=login.cookies,headers={"X-Requested-With":"XMLHttpRequest","User-Agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.30 Safari/536.5"}).content)
for wallpaper in a:
url = "http://wallbase.cc/wallpaper/"+str(wallpaper['id'])
colorpage = colored(str(page),"blue")
colorwidth = colored(str(wallpaper['attrs']['wall_w']), "blue")
colorheight = colored(str(wallpaper['attrs']['wall_h']), "blue")
print colorpage + ".\t" + url + "\tWidth: " + colorwidth + "\tHeight: " + colorheight
try:
soup = BeautifulSoup(requests.get(url,cookies=login.cookies).content)
img = soup.findAll("img")
urllib.urlretrieve(img[len(img)-1].get("src"),str(page) + "." + img[len(img)-1].get("src").split(".")[-1])
except:
cprint("FAILED!","red",attrs=["bold"])
page=page+1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment