#!/usr/bin/python
# Created 4/8/09 by Daedalus
# http://fublag.wordpress.com
# actaeus@gmail.com
import urllib, httplib, sys
def main(argv=None):
while 1:
if argv:
q = argv
else:
q = raw_input("> ")
query=urllib.urlencode({'q':q})
start='
'
end=''
google=httplib.HTTPConnection("www.google.com")
google.request("GET","/search?"+query)
search=google.getresponse()
data=search.read()
if data.find(start)==-1: print "Google Calculator results not found."
else:
begin=data.index(start)
result=data[begin+len(start):begin+data[begin:].index(end)]
result = result.replace(" ",",").replace(" × 10","E").replace("","").replace("\xa0",",")
print result
if argv: break
if __name__ == "__main__":
try: main(sys.argv[1])
except: main()