Created
June 13, 2009 04:33
-
-
Save jcsalterego/129098 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| import re | |
| import sys | |
| import urllib2 | |
| SIZE = "1920x1200" | |
| DOMAIN = "http://interfacelift.com" | |
| URL_FMT = "%s/wallpaper_beta/downloads/date/hdtv/index%%d.html" % DOMAIN | |
| def info(msg, newline = True): | |
| sys.stderr.write(msg) | |
| if newline: | |
| sys.stderr.write("\n") | |
| def html_get(url): | |
| conn = urllib2.urlopen(url) | |
| return conn.read() | |
| def main(): | |
| # get first page | |
| first = html_get(URL_FMT % 1) | |
| pages_rex = re.compile("page 1 of ([0-9]+)") | |
| matches = pages_rex.findall(first) | |
| if not len(matches): | |
| info("Error on reading pages!") | |
| total = int(matches[0]) | |
| info("%d page(s) found!" % total) | |
| wp_rex = re.compile('<a href="(/wallpaper_beta/dl/[^"]+)"') | |
| counter = 1 | |
| html = first | |
| print "#!/bin/sh" | |
| while counter <= total: | |
| info("Downloading page %d of %d..." % (counter, total), newline=False) | |
| matches = wp_rex.findall(html_get(URL_FMT % counter)) | |
| info("%d wallpapers found." % len(matches)) | |
| print "# Page %d of %d (%d items)" % (counter, total, len(matches)) | |
| for match in matches: | |
| match = match.replace("1920x1080", SIZE) | |
| url = "".join((DOMAIN, match)) | |
| req = urllib2.urlopen(url) | |
| print url | |
| for i in req.headers.items(): | |
| print i | |
| if 'location' not in req.headers: | |
| continue | |
| url = req.headers['location'] | |
| print "wget %s" % url | |
| counter += 1 | |
| return 0 | |
| if __name__ == '__main__': | |
| sys.exit(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment