Jake.codes

Re-Search in DuckDuckGo, for Pythonista

Sunday, October 27, 2013

# -*- coding: utf-8 -*-
# Re-search in DuckDuckGo
# By Jake Bilbrey
# jakebilbrey.com
#
# Accidentally searched using one of
# default search engines on your iPhone
# or iPad? Let's try that again, but with
# the great DuckDuckGo.
#
# javascript:location.href='pythonista://Re-search?action=run&argv='+encodeURIComponent(location.href);
#
import sys
import re
import console
import webbrowser

searchText = sys.argv[1]
searchText = 'safari-https://duckduckgo.com/' + re.search("\?(q|p)=.+?(?=&)", searchText, re.I).group(0)
searchText = searchText.replace('?p=', '?q=')

console.clear()
print searchText

webbrowser.open(searchText)