Beispiel #1
0
 def searchJoke(query=None):
     if query:
         tree = Utils.crawlUrl('http://www.piadasnet.com/index.php?pesquisaCampo=%s&btpesquisa=OK&pesquisaInicio=0' % quote(query.encode('utf-8')))
     else:
         tree = Utils.crawlUrl('http://www.piadasnet.com/')
     jokeTags = tree.xpath('//p[contains(@class, "piada")]')
     return map(lambda t: t.text_content(), jokeTags)
Beispiel #2
0
 def getNasaIOD():
     tree = Utils.crawlUrl('http://apod.nasa.gov')
     imageTags = tree.xpath('//img[contains(@src,"image")]')
     pTags = tree.xpath('//p')
     if imageTags and len(pTags) >= 3:
         result = { 'imageSource': 'http://apod.nasa.gov/%s' % imageTags[0].attrib['src'], 'explanation': pTags[2].text_content() }
         return result
     else:
         return None
Beispiel #3
0
 def logWarning(self, message):
     Utils.logWarning(self.bot, self.__class__.__name__, message)
Beispiel #4
0
 def logDebug(self, message):
     Utils.logDebug(self.bot, self.__class__.__name__, message)
Beispiel #5
0
 def sendMessage(self, **kargs):
     channel = kargs.get('chat_id')
     text = kargs.get('text') or ''
     Utils.logDebug(self, self.__class__.__name__, 'sendMessage %s' % kargs)
     self.slackClient.api_call('chat.postMessage', channel=channel, as_user=True, username=self.getInfo().username, icon_emoji=':robot_face:', text=text.encode('utf-8'))
Beispiel #6
0
 def searchBingImage(query):
     tree = Utils.crawlUrl('http://www.bing.com/images/search?q=%s' % quote(query.encode('utf-8')))
     imageTags = tree.xpath('//img[contains(@src, "bing.net")]')
     imageSources = map(lambda img: img.attrib.get('src'), imageTags)
     return imageSources
Beispiel #7
0
 def searchGoogleImage(query):
     query = query.encode('utf-8')
     tree = Utils.crawlUrl('https://www.google.com.br/search?site=&tbm=isch&q=%s&oq=%s&tbs=isz:l' % (quote(query), quote(query)))
     imageTags = tree.xpath('//img[contains(@src, "gstatic")]')
     imageSources = map(lambda img: img.attrib.get('src'), imageTags)
     return imageSources
Beispiel #8
0
 def sendMessage(self, **kargs):
     Utils.logDebug(self, self.__class__.__name__, 'sendMessage %s' % kargs)
     self.telegramBot.sendMessage(**kargs)