import webbrowser
import subprocess
import re
import urllib
dankly = "xclip -o"
process = subprocess.Popen(dankly.split(), stdout=subprocess.PIPE)
output = process.communicate()[0]
if output == "":
    dialog.info_dialog(title="Error: No Select Available", message="It seems as if you haven't selected content to use with this 
autokey. Please highlight a term or phrase to search in order to use this menu item.")
    exit()
else:
    if clipboard.get_selection() == "":
        retCode, ggl = dialog.input_dialog("Kbase Search", "What do you want to search for?", default='')
    else:
        text = clipboard.get_selection()
        retCode, ggl = dialog.input_dialog("Kbase Search", "What do you want to search for?", default=''+text)
    if retCode ==1:
        exit()
    ggl = urllib.quote_plus(ggl)
    dankly = "whoami"
    process = subprocess.Popen(dankly.split(), stdout=subprocess.PIPE)
    output = process.communicate()[0]
    bark = re.sub(r'\W+', '', output)
    webbrowser.open_new_tab('http://isaac.staff.hostgator.com/post.php?serd='+ggl+'&who='+bark)
