def bestRelatedWord(self, emotion): scores = [] for word in self.relatedWords: newWord = replaceSpace(word) cursor = conn.yahoo.find({'word':newWord}) if cursor.count() == 0: yahoo.getQuestions(newWord) score = yahoo.getWordScore(newWord, emotion) scores.append((replacePlus(newWord), score)) scores = sorted(scores, key=lambda x: x[1]) scores.reverse() if scores: return scores
def bestRelatedWord(self, emotion): scores = [] for word in self.relatedWords: newWord = replaceSpace(word) cursor = conn.yahoo.find({'word': newWord}) if cursor.count() == 0: yahoo.getQuestions(newWord) score = yahoo.getWordScore(newWord, emotion) scores.append((replacePlus(newWord), score)) scores = sorted(scores, key=lambda x: x[1]) scores.reverse() if scores: return scores
def __init__(self,word, numQuestions, numAnswers, emotions, numPeople): self.numQuestions = int(numQuestions) self.word = word self.numAnswers = int(numAnswers) self.emotions = emotions self.numPeople = int(numPeople) self.speaker = 1 self.questioner = None self.lines = [] self.script = [] questions = database.find({'word':word}) if questions.count() == 0: print 'here' yahoo.getQuestions(word) self.questions = yahoo.getGoodQuestions('numSnarkyAnswers',self.word).limit(self.numQuestions) for question in self.questions: self.addQuestionToScript(question, self.emotions)
def getQuestions(self, topics): for topic in topics: if (self.source == "Reddit"): if (self.skipDownload): questions = defaultQuestions comments = defaultComments else: questions = [] comments = [] # check number of questions in the database topic_questions = question_database.find({'topic': topic}) if topic_questions.count() < (self.questionCount): reddit.getMoreQuestions(topic) topic_questions = question_database.find( {'topic': topic}) questions = topic_questions comments = comment_database.find({'topic': topic}) #for ii in range(0, self.questionCount): #questions.append(reddit.getQuestion(topic)) #comments.append(reddit.getComments(questions[ii], topic)) for ii in range(0, self.questionCount): commentOffset = 0 dirtyOffset = 0 for actor in self.actors: if (actor.emotion == "questions"): rand_question = random.randint( 0, questions.count() - 1) if (self.skipDownload): actor.responses.append( questions[rand_question]['question']) else: actor.responses.append( questions[rand_question]['question']) else: #actor.responses.append(reddit.getDirtyComments(comments[ii])[dirtyOffset]) emotion_comments = reddit.getEmotionComments( topic, actor.emotion) for c in emotion_comments: # print(c['text']) actor.responses.append(c['text']) # dirtyOffset += 1 #else: # actor.responses.append(comments[ii][commentOffset]) # commentOffset += 1 #print("\n\nResponses:\n") #print(actor.responses) elif (self.source == "Yahoo"): questions = yahoo.getQuestions(topic) quest = yahoo.getGoodQuestions("numGoodAnswers", topic).limit(1) for actor in self.actors: for q in quest: actor.responses.append(q[actor.emotion][0]['text']) print("\n\nResponses:\n") print(actor.responses) print("Done")
def main(argv): numActors = int(argv[0]) topics = argv[1:] #pool = get_comments.GetCommentPool(topics[0]) #pool = ["hello"] #yahoo.getQuestions(topics[0]); #linkCursor = yahoo.database.find({'word': topics[0]}) #print(linkCursor.count()) pool = [] answers = [] allQuestions = [] dirtyAnswers = [] snarkyAnswers = [] positiveAnswers = [] questions = yahoo.database.find({'word': topics[0]}) if questions.count() < 10: print("not enough questions") yahoo.getQuestions((topics[0])) goodQuestions = yahoo.getGoodQuestions('dirtyAnswers', topics[0]).limit(20) for quest in goodQuestions: allQuestions.append(quest['title']) allQuestions.append(quest['question']) for a in quest['answers']: dirtyAnswers.append(a) #print(a['text']) goodQuestions = yahoo.getGoodQuestions('snarkyAnswers', topics[0]).limit(20) for quest in goodQuestions: allQuestions.append(quest['title']) allQuestions.append(quest['question']) for a in quest['answers']: snarkyAnswers.append(a) #print(a['text']) goodQuestions = yahoo.getGoodQuestions('positiveAnswers', topics[0]).limit(20) for quest in goodQuestions: allQuestions.append(quest['title']) allQuestions.append(quest['question']) for a in quest['answers']: positiveAnswers.append(a) #print(a['text']) if (pool.__len__() == 0): exit("No results") lines = [] #print("Comment pool:") for str in pool: if str['type'] == 'question': #print(str['text']) lines.append(str['text']) if str['type'] == 'title': #print(str['text']) lines.append(str['text']) if str['type'] == 'answer': lines.append(str['text']) manager = StageManager(numActors, topics, lines) manager.produceScript(topics) manager.script.printScript()