json = result[0]
self.msg(channel, '[Google] @b%(title)s@b <@u%(url)s@u>' % {
- 'title': unescape(json['titleNoFormatting']),
+ 'title': unescape(json['titleNoFormatting']),
'url': json['unescapedUrl']})
if json['content'] != '':
self.msg(channel, '[Google] @bDescription@b: %s' % unescape(json['content']).replace('<b>', '@b').replace('</b>', '@b'))
+def command_google_image_search(self, manager, opts, arg, channel, sender, userinfo):
+ try:
+ result = self.google.image_search(arg, userinfo['ip'] if userinfo['ip'] != '0' else '255.255.255.255')
+ except FeedError, e:
+ self.errormsg(channel, e.msg)
+ return
+
+ if result['responseStatus'] == 403:
+ self.elog.warning('WARNING: Google Image Search failed: %s' % result['responseDetails'] if 'responseDetails' in result else 'unknown error')
+ self.notice(sender, 'Google Search is temporarily unavailable. Try again later.')
+ return
+
+ result = result['responseData']['results']
+ if not result:
+ self.msg(channel, '[Google Image] No results found')
+ return
+
+ json = result[0]
+ self.msg(channel, '[Google Image] @b%(title)s@b <@u%(url)s@u>' % {
+ 'title': unescape(json['titleNoFormatting']),
+ 'width': json['width'],
+ 'height': json['height'],
+ 'url': json['unescapedUrl']})
+
+ self.msg(channel, '[Google Image] @bSize@b: %(width)sx%(height)spx%(desc)s' % {
+
+ 'width': json['width'],
+ 'height': json['height'],
+ 'desc': (' - @bDescription@b: %s' % unescape(json['content']).replace('<b>', '@b').replace('</b>', '@b')) if json['content'] else ''})
+
+
def command_calc(self, manager, opts, arg, channel, sender, userinfo):
try: # local calculation using PyParsing
result = self.nsp.eval(arg)
'g': 'google',
'google': (command_google_search, ARG_YES, 'Search for something on Google', [], 'google_search'),
+ 'gi': 'google_image',
+ 'google_image': (command_google_image_search, ARG_YES, 'Search for images via Google Image', [], 'google_image_search'),
+
't': 'translate',
'translate': (command_bing_translate, ARG_YES, 'Translate something from a language to another', [], 'from to text'),