-
-
Save coleifer/e5f5e78aeceb6b4d078f to your computer and use it in GitHub Desktop.
This file contains 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 | |
""" | |
Usage: | |
$ python find-wallpapers.py | |
Example output: | |
http://i.imgur.com/THbJKaZ.png | |
""" | |
import re | |
import subprocess | |
COLORS_R = re.compile('.*?color([\d]+):\s*?(#[A-Fa-f0-9]+)') | |
COLOR_NAMES = [ | |
'black', | |
'red', | |
'green', | |
'yellow', | |
'blue', | |
'magenta', | |
'cyan', | |
'white', | |
'alt_black', | |
'alt_red', | |
'alt_green', | |
'alt_yellow', | |
'alt_blue', | |
'alt_magenta', | |
'alt_cyan', | |
'alt_white', | |
] | |
URL_TEMPLATE = 'http://wallbase.cc/search?q=&color=%s§ion=wallpapers&order_mode=desc' | |
def read_colors(): | |
xrdb = subprocess.Popen(['xrdb', '-q'], stdout=subprocess.PIPE) | |
out, _ = xrdb.communicate() | |
return dict( | |
(int(idx), val) for idx, val in COLORS_R.findall(out)) | |
def main(): | |
colors = read_colors() | |
print 'Colors\n------' | |
for color, hexval in sorted(colors.items()): | |
term_color = (color % 8) + 30 | |
if color >= 8: | |
escape = '1;%sm' % term_color | |
else: | |
escape = '%sm' % term_color | |
print '\033[%s%s\033[0m: %s' % ( | |
escape, | |
COLOR_NAMES[color], | |
URL_TEMPLATE % hexval[1:]) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment