Created
January 20, 2013 23:28
-
-
Save LeoAdamek/4582561 to your computer and use it in GitHub Desktop.
A Wallbase downloader with lotsa options. Writing it to set a cron job for `feh`
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/python | |
| import re | |
| import argparse | |
| from pyquery import PyQuery as Q | |
| from lxml import etree | |
| def main(): | |
| opts = parse_args() | |
| url = 'http://wallbase.cc/' | |
| if opts.query_type.lower() != 'search': | |
| if opts.query_type.lower() == 'random': | |
| url += 'random/all/' | |
| else: | |
| url += 'toplist/0/all/' | |
| if opts.exact: | |
| url += 'eqeq/' | |
| else: | |
| url += 'gteq/' | |
| if not re.match("^\d+x\d+$", opts.res): | |
| print "[Error] Resolution must be in format AxB" | |
| return | |
| else: | |
| url += "%s/" % opts.res | |
| page = Q(url=url) | |
| wallpaper_url = page('div#thumbs div.thumb:first a.thlink').attr.href | |
| else: | |
| url += 'search' | |
| def parse_args(): | |
| parser = argparse.ArgumentParser(description="Wallbase Background Scraper") | |
| parser.add_argument('--query-type', type=str, help="Query type, either 'Search', 'Random' or 'Popular'") | |
| parser.add_argument('--res', type=str, help="Resolution in format AxB") | |
| parser.add_argument('--exact', action='store_true', help="Query for Exact resolution match?", required=False) | |
| parser.add_argument('--sketchy', action='store_true', help="Include 'Sketchy' images?", required=False) | |
| parser.add_argument('--popular-range', type=str, help="For popular, set popular time", required=False) | |
| parser.add_argument('--query', type=str, nargs='+', help="Search term", required=False) | |
| return parser.parse_args() | |
| if __name__ == '__main__': | |
| main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment