This repository was archived by the owner on Oct 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.en.py
107 lines (92 loc) · 3.07 KB
/
index.en.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
106
107
from chatbot import Chat, register_call
import wikipedia
import duckduckpy
import os
import time
import warnings
import subprocess
import datetime
import sys
from googletrans import Translator
translator = Translator()
if len(sys.argv) < 2:
print('You need to specify the path to be listed')
sys.exit()
input = sys.argv[1]
print(input)
warnings.filterwarnings("ignore")
def speak(msg):
subprocess.call(["./simple-google-tts/simple_google_tts", "en", msg])
def get_time():
return time.strftime('%l:%M')
def get_date():
today = datetime.date.today()
return today.strftime("%b %d %Y")
def get_day():
today = datetime.date.today()
return today.strftime("%A")
class MyChat(Chat):
def converse(self, first_question=None, quit="quit", session_id="general"):
"""
Conversation initiator
:type first_question: str
:param first_question: Start up message
:type quit: str
:param quit: Conversation termination command
:type session_id: str
:param session_id: Current User session when used for multi user scenario
:rtype: str
"""
if first_question:
self.conversation[session_id].append(first_question)
message = self.respond(first_question, session_id=session_id)
speak(message)
""" Only for command-line usage
input_sentence = ""
while input_sentence != quit:
# Read Input source
input_sentence = input("> ")
if input_sentence:
self.conversation[session_id].append(input_sentence)
input_sentence = input_sentence.rstrip("!.")
message = self.respond(input_sentence, session_id=session_id)
self.conversation[session_id].append(message)
# call output function
print(message)
speak(message)
"""
@register_call("duckduckgo")
def google_it(q, session_id="general"):
response = duckduckpy.query(q, container="dict")
if(len(response["related_topics"]) > 0):
for result in response["related_topics"]:
print("Text: "+result["text"])
print("URL: "+ result["first_url"])
return "Here's some results from DuckDuckGo"
else:
return "No results found"
@register_call("liver")
def liver(query, session_id="general"):
return "Ok, here you go"
@register_call("specific")
def spec(query, session_id="general"):
query = query.strip()
specification = {
"time": get_time(),
"date": get_date(),
"day": get_day()
}
return specification.get(query, "I have no idea.")
@register_call("whoIs")
def who_is(query, session_id="general"):
try:
return wikipedia.summary(query)
except Exception:
for new_query in wikipedia.search(query):
try:
return wikipedia.summary(new_query)
except Exception:
pass
return "I don't know about "+query
chat = MyChat(os.path.join(os.path.dirname(os.path.abspath(__file__)), "bot.template"))
chat.converse(input)