def checkCommand(self, command, arguments): if command.lower() in ["stackoverflow", "stack", "so"]: self.searchResults = {} urls = [ x[2] for x in google_search(self.query + arguments) ] if isinstance(urls, str): print(urls) return self.noAnswers if len(urls) == 0: return self.noAnswers # no answers else: ID=1 for url in urls: answers=[] dom = self.parser.parse(requests.get(url).text) for answer in dom.findall(self.answerPath): answers.append((''.join(["%s\n"%txt.strip() for txt in answer.itertext()])).strip()) if len(answers) != 0: self.searchResults[ID]={"url": url, "answers":answers} ID+=1 reply=[] for r in self.searchResults.keys(): reply.append("%s\n%s"%(self.searchResults[r]['url'], self.searchResults[r]['answers'][0])) return reply
def checkCommand(self, command, arguments): if command.lower() in ["google", "g"]: result=google_search(arguments) if not result: return self.default else: reply=[] self.searchResults={} ID=1 for r in result: reply.append("(%s) %s\n%s"%(ID, r[0], r[1])) self.searchResults[ID]=r ID+=1 return reply elif command.lower() in ["google-open", "gopen"]: if not arguments: return self.noID try: _id=int(arguments.split()) return "%s\n%s\n%s"%(self.searchResults[_id]) except: return self.wrongID