-
Notifications
You must be signed in to change notification settings - Fork 0
/
Greeting.py
50 lines (48 loc) · 1.52 KB
/
Greeting.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
# !/usr/bin/env python
#@Author: Prem Narain
from twisted.internet import reactor
from starpy import fastagi
import logging
from datetime import datetime
from random import choice
# log = logging.getLogger( 'Greeting')
class Online():
"""
5 to 11:59am Good Morning
12 to 17:59pm Good Noon
18 to 20:59pm Good Evening
21 to 4:59am Good Night
"""
def __init__(self):
self.gret=["Hello","Hi","Hey"]
self.morning = ["Good morning"]
self.noon=["Good afternoon","Good Noon"]
self.evening = ["Good evening"]
self.night=["Good Night"]
def random(self):
if datetime.now().hour<12:
return choice(self.gret) + choice(self.morning)
if (datetime.now().hour>12) or (datetime.now().hour< 18):
return choice(self.gret) + choice(self.noon)
if (datetime.now().hour>18) or (datetime.now().hour< 21):
return choice(self.gret) + choice(self.evening)
if (datetime.now().hour>21) or (datetime.now().hour<5):
return choice(self.gret) + choice(self.night)
def Greetingflow(agi):
online=Online()
log.debug('Greeting of the day')
Myflow = fastagi.InSequence()
Myflow.append( agi.answer)
Myflow.append(agi.sayAlpha,online.random())
Myflow.append(agi.finish)
def onFailure( reason ):
log.error( "Failure: %s", reason.getTraceback())
agi.finish()
return Myflow().addErrback( onFailure )
if __name__ == "__main__":
logging.basicConfig()
fastagi.log.setLevel(logging.DEBUG )
f = fastagi.FastAGIFactory(Greetingflow)
print ("Listening!")
reactor.listenTCP(4573, f, 50, '127.0.0.1') # only binding on local interface
reactor.run()