JCarlin6
February 2nd, 2011, 11:59 PM
In previous versions it worked but I downloaded them and re-ran them and they no longer work. They get to the images url and starts the download but it stops at 213 kb's EVERYTIME was there a update to python that I didnt see? Does this still work for anyone and if so what is your current python version??
#!/usr/bin/python
# Required modules
import urllib, random, xml.dom.minidom, re, os, glob, time;
class Wallbase:
url = 'http://wallbase.net/random/all/gteq/1366x768/0/110/60';
urlResponse = None;
urlRequest = None;
# Get HTML
def getHtml(self, url):
# Get HTML
self.urlRequest = urllib.URLopener().open(url);
# Set HTML
self.urlResponse = self.urlRequest.read();
# Close URL request
self.urlRequest.close();
return self.urlResponse;
# Get random wallpaper URL
def getRandomWallpaperUrl(self, url):
# Get HTML
html = self.getHtml(url);
# Create new DOM Document
dom = xml.dom.minidom.parseString(html);
# Get all images
anchors = dom.getElementsByTagName('a');
# No anchors found
if anchors.length < 1:
return;
# New thumbs array
thumbs = [];
# Iterate over anchors
for anchor in anchors:
# Get attribute source
href = anchor.getAttribute('href').encode('ascii', 'ignore');
# Does it match thumb format?
if re.search(r'wallpaper/\d+$', href):
thumbs.append(href); # Append source to array
# Random wallpaper url
return random.choice(thumbs);
# Set a random wallpaper
def setRandomWallpaper(self):
# Set wallpaper
self.setWallpaper(self.getRandomWallpaperUrl(self. url));
# Set a user specified wallpaper (pointless)
def setWallpaper(self, url):
os.system('cp '+self.getWallpaper(url)+' /home/alpha/wallpapers/wallpaper');
# Get random wallpaper
def getWallpaper(self, url):
print 'Getting Wallpaper: ' + url;
# Get HTML
html = self.getHtml(url);
# Create new DOM Document
dom = xml.dom.minidom.parseString(html);
# Get all images
imgs = dom.getElementsByTagName('img');
# No images found
if imgs.length < 1:
return;
# Iterate over images
for img in imgs:
# Get attribute source
src = img.getAttribute('src').encode('ascii', 'ignore');
# Does it match wallpaper format?
if re.search(r'/wallpaper-\d+\.(?i)(?:gif|png|jpe?g)$', src):
# Generate save path
name = '/home/alpha/wallpapers' + src[src.rfind('/'):];
# Does wallpaper already exist?
if os.path.exists(name) == False:
# Fetch image and save it
urllib.urlretrieve(src, name);
# Return wallpaper name
return name;
# New Wallbase instance
wallbase = Wallbase();
# Set random Wallbase wallpaper
wallbase.setRandomWallpaper();
================================================
#!/usr/bin/python
# Required modules
import urllib, random, xml.dom.minidom, re, os, glob, time;
class Wallbase:
url = 'http://wallbase.net/random/all/gteq/1366x768/0/110/60';
urlResponse = None;
urlRequest = None;
# Get HTML
def getHtml(self, url):
# Get HTML
self.urlRequest = urllib.URLopener().open(url);
# Set HTML
self.urlResponse = self.urlRequest.read();
# Close URL request
self.urlRequest.close();
return self.urlResponse;
# Get random wallpaper URL
def getRandomWallpaperUrl(self, url):
# Get HTML
html = self.getHtml(url);
# Create new DOM Document
dom = xml.dom.minidom.parseString(html);
# Get all images
anchors = dom.getElementsByTagName('a');
# No anchors found
if anchors.length < 1:
return;
# New thumbs array
thumbs = [];
# Iterate over anchors
for anchor in anchors:
# Get attribute source
href = anchor.getAttribute('href').encode('ascii', 'ignore');
# Does it match thumb format?
if re.search(r'wallpaper/\d+$', href):
thumbs.append(href); # Append source to array
# Random wallpaper url
return random.choice(thumbs);
# Set a random wallpaper
def setRandomWallpaper(self):
# Set wallpaper
self.setWallpaper(self.getRandomWallpaperUrl(self. url));
# Set a user specified wallpaper (pointless)
def setWallpaper(self, url):
os.system('cp '+self.getWallpaper(url)+' /home/alpha/wallpapers/wallpaper');
# Get random wallpaper
def getWallpaper(self, url):
print 'Getting Wallpaper: ' + url;
# Get HTML
html = self.getHtml(url);
# Create new DOM Document
dom = xml.dom.minidom.parseString(html);
# Get all images
imgs = dom.getElementsByTagName('img');
# No images found
if imgs.length < 1:
return;
# Iterate over images
for img in imgs:
# Get attribute source
src = img.getAttribute('src').encode('ascii', 'ignore');
# Does it match wallpaper format?
if re.search(r'/wallpaper-\d+\.(?i)(?:gif|png|jpe?g)$', src):
# Generate save path
name = '/home/alpha/wallpapers' + src[src.rfind('/'):];
# Does wallpaper already exist?
if os.path.exists(name) == False:
# Fetch image and save it
urllib.urlretrieve(src, name);
# Return wallpaper name
return name;
# New Wallbase instance
wallbase = Wallbase();
# Set random Wallbase wallpaper
wallbase.setRandomWallpaper();
================================================