Skip to content

Instantly share code, notes, and snippets.

@coleifer
Last active August 29, 2015 13:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coleifer/e5f5e78aeceb6b4d078f to your computer and use it in GitHub Desktop.
Save coleifer/e5f5e78aeceb6b4d078f to your computer and use it in GitHub Desktop.
#!/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&section=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