-
Notifications
You must be signed in to change notification settings - Fork 1
/
yahooScene.py
105 lines (81 loc) · 2.71 KB
/
yahooScene.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import yahoo
from pymongo import Connection, DESCENDING, ASCENDING
global conn
conn = Connection().Theater
global database
database = conn.yahoo
class YahooScene:
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 addAnswerToScript(self, question, emotion):
answerList = question[emotion]
sorter = emotion[:-7]+'Score'
if sorter == 'goodScore':
answerList = sorted(answerList, key=lambda k: k['dirtyScore'])
anserList.reverse()
else:
answerList = sorted(answerList, key=lambda k: k[sorter])
answerList.reverse()
for i in range(len(answerList)):
if answerList[i] not in self.lines:
#answerList[i]['text'] = emotion + " " + str(len(answerList))+ " " + answerList[i]['text']
self.lines.append(answerList[i])
break
def addQuestionToScript(self, question, emotions):
self.lines.append(question['title'])
self.lines.append(question['question'])
emotion = 0
for i in range(self.numAnswers):
if emotion == len(emotions):
emotion = 0
self.addAnswerToScript(question, emotions[emotion])
emotion += 1
def changeSpeaker(self):
if self.speaker == self.numPeople:
self.speaker = 1
else:
self.speaker += 1
def speak(self, line, change = False):
if line == '<br>':
finalLine = '<br>'
else:
finalLine = "<b>ACTOR " + str(self.speaker) + "</b>: " + line + "<br>"
if change:
self.changeSpeaker()
return finalLine
def makeScript(self):
for line in self.lines:
if line['type'] == 'title':
finalLine = self.speak("QUESTION: " + line['text'])
self.questioner = self.speaker
self.script.append(finalLine)
if line['type'] == 'question':
finalLine = self.speak(line['text'], True)
while self.speaker == self.questioner:
self.changeSpeaker()
self.script.append(line['text']+'<br>')
self.script.append('<br>')
if line['type'] == 'answer':
finalLine = self.speak(line['text'], True)
while self.speaker == self.questioner:
self.changeSpeaker()
self.script.append(finalLine)
self.script.append('<br>')
if __name__ == '__main__':
scene = YahooScene("sexy",3,3,['positiveAnswers','snarkyAnswers'],3)
scene.printScript()