Skip to content

Instantly share code, notes, and snippets.

@gabrielfalcao
Created January 22, 2015 21:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gabrielfalcao/ea461138f0879cb2fa5b to your computer and use it in GitHub Desktop.
Save gabrielfalcao/ea461138f0879cb2fa5b to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
from __future__ import unicode_literals
import os
import sys
import requests
url = 'http://ajax.googleapis.com/ajax/services/search/images'
def search(name):
params = {
'v': '1.0',
'rsz': '8',
'q': '{0} github'.format(name),
'safe': 'active',
'imgtype': 'face'
}
response = requests.get(url, params=params)
data = response.json()
results = data['responseData']['results']
return results[0]['unescapedUrl']
def utf8(s):
return s.decode('utf-8')
if __name__ == '__main__':
name = " ".join(map(utf8, sys.argv[1:]))
url = search(name)
os.system('open {0}'.format(url))
@gabrielfalcao
Copy link
Author

USAGE:

python github-google-image-search.py Linus Torvalds

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment