-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
53 lines (47 loc) · 1.59 KB
/
bot.py
File metadata and controls
53 lines (47 loc) · 1.59 KB
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
import os
class Bot():
"""Bot class"""
def __init__(self, result):
try:
self.result = result[0]
except Exception as e:
self.result = None
self.answers = {
'positive': 'Oh, that\'s very kind of you',
'neutral': 'Interesting. Ok.',
'negative': 'I feel so bad about what you wrote',
}
self.positiveEmotions = ['joy']
self.negativeEmotions = ['anger', 'fear', 'sadness']
self.path = os.getcwd() + '/moodCounter.txt'
def reply(self):
"""This is returning the final answer"""
if self.result in self.negativeEmotions:
return self.answers['negative']
elif self.result in self.positiveEmotions:
return self.answers['positive']
else:
return self.answers['neutral']
def evalMood(self):
"""Evaluate Mood (positive, negative, neutral)"""
moodLevel = self.readFile()
if self.result in self.negativeEmotions:
moodLevel -= 1
elif self.result in self.positiveEmotions:
moodLevel += 1
self.writeFile(moodLevel)
def getMood(self):
moodLev = self.readFile()
if moodLev > 0:
return 'positive'
elif moodLev < 0:
return 'negative'
else:
return 'neutral'
def readFile(self):
with open(self.path, 'r') as handle:
content = handle.read()
return int(content)
def writeFile(self, content):
with open(self.path, 'w') as handle:
handle.write(str(content))