Last active
December 12, 2015 03:28
-
-
Save hiway/4706506 to your computer and use it in GitHub Desktop.
Uses a [deprecated?] Google API to search for your query and returns URL of the first result. I use this with TextExpander to quickly put in URLs of services I'm mentioning in chats, emails or blog posts.
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 | |
# -*- coding: utf-8 -*- | |
import requests | |
import json | |
import sys | |
def get_search_results(query): | |
url = "http://ajax.googleapis.com/ajax/services/search/web" | |
payload = dict( | |
v='1.0', | |
rsz='large', | |
q=query, | |
) | |
r = requests.get(url, params=payload) | |
return json.loads(r.text) | |
r = get_search_results(' '.join(sys.argv[1:])) | |
print r['responseData']['results'][0]['url'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment