#NEWLINE# @ respond_to ( 'image me (?P<search_query>.*)$' ) #NEWLINE# def image_me( self , message , search_query ) : #NEWLINE# #INDENT# 'image me ___ : Search google images for ___, and post a random one.' #NEWLINE# data = { #NEWLINE# #INDENT# 'q' : search_query , #NEWLINE# 'v' : '1.0' , #NEWLINE# 'safe' : 'active' , #NEWLINE# 'rsz' : '8' , #NEWLINE# #UNINDENT# } #NEWLINE# r = requests . get ( 'http://ajax.googleapis.com/ajax/services/search/images' , params = data ) #NEWLINE# try : #NEWLINE# #INDENT# results = r . json ( ) [ 'responseData' ] [ 'results' ] #NEWLINE# #UNINDENT# except TypeError : #NEWLINE# #INDENT# results = [ ] #NEWLINE# #UNINDENT# if ( len ( results ) > 0 ) : #NEWLINE# #INDENT# url = random . choice ( results ) [ 'unescapedUrl' ] #NEWLINE# self . say ( ( '%s' % url ) , message = message ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . say ( "Couldn't find anything!" , message = message )