Search Google & GitHub from Pythonista

I’m a hack. I’ll admit it. I spend more time trying to figure out why my scripts don’t work than I actually do writing the code.

To that end, I got sick of going back and forth from Safari to Pythonista and back on my iOS devices. So I created a little script to search both Google and GitHub from within Pythonista’s built-in browser. I did have StackExchange in there too, but took it out because if it has a good answer, it’s usually towards the top of the Google results.

Again, the easiest way to get this into Pythonista is to copy the link to the gist to your clipboard and then use Ole Zorn’s New from Gist Script. If you’re using Workflow, maybe the easiest way is to install my New from Gist workflow and run it the workflow from Safari.

#coding: utf-8  
A little script to search Google or GitHub right from inside Pythonista.  
I added the script to the action menu so I can do a quick search without leaving Pythonista.  
I find this especially helpful if I'm researching some error my script is throwing.  

import webbrowser  
import console  
import urllib  
import re

def SiteSearch(term,service):  
    if service == 1:  
        tencode = urllib.quote(term)  
        url = '' + tencode  
    elif service == 2:  
        tencode = re.sub('\s','+',term)  
        url = '' + tencode  
    elif service == 3:  
        tencode = re.sub('\s','+',term)  
        url = '' + tencode  
        console.hud_alert('Please select a service to search.','error')

term = console.input_alert('Search Term')  
service = console.alert('where would you like to search?','','Google','GitHub (Gist)','GitHub (Repo)',)

#url = '' + tencode


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s