-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain2.py
156 lines (124 loc) · 3.94 KB
/
main2.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import sys
import os
import threading as thread
from chatbot import *
import aiml
import time
import json
from difflib import get_close_matches
import datetime as dt
import random as rd
from wikipedia import *
import webbrowser
from wikiHow import *
def browser(query):
try:
webbrowser.open('www.'+query+'.com')
return "Opening Browser"
except:
return "Please check your Internet connection!"
def search(query):
try:
webbrowser.open_new('www.google.com/search?q=' + query)
return "Searching in Browser"
except:
return "Please check your Internet connection!"
def navigate(query):
try:
webbrowser.open_new('www.google.com/search?q=navigate+to+' + query)
return "Okay!"
except:
return "Please check your Internet connection!"
def navigateing(query):
try:
webbrowser.open_new('www.google.com/search?q=' + query)
return "Okay!"
except:
return "Please check your Internet connection!"
#normal wiki command
def wikip(n):
try:
q=wikipedia.summary(n, sentences=4)
return q
except:
return "please rephrase your statement"
dice = ['1', '2', '3', '4', '5', '6']
coin = ['Heads', 'Tails']
def toss():
rd.choice(coin)
return "You got "+ rd.choice(coin)
def throw():
return "You got "+rd.choice(dice)
k = aiml.Kernel()
k.learn("database/std-startup.xml")
k.respond("load aiml b")
data = json.load(open("database/data.json"))
def extras_spam(n):
q = k.respond(n)
if q =="damm":
q = response(n)
return q
else:
return q
def dictionarry(w):
if w in data:
return data[w][0]
elif w.title() in data:
return data[w.title()][0]
elif len(get_close_matches(w, data.keys())) > 0:
print(get_close_matches(w, data.keys())[0])
return dictionarry(get_close_matches(w, data.keys())[0])
else:
return "The word doesn't exist. Please double check it."
def listToString(s):
str1 = ""
for ele in s:
str1 += ele
return str1
def search_for_n(n):
if "tell me the meaning of" in n:
n = n.replace("tell me the meaning of ","")
q = dictionarry(n)
return q
elif "how to" in n:
try:
max_results = 1
how_tos = search_wikihow(n, max_results)
assert len(how_tos) == 1
d = how_tos[0].print()
print(d)
return d
except:
return search(n)
elif "what is the meaning of" in n:
n = n.replace("tell me the meaning of ","")
q = dictionarry(n)
return q
elif "meaning of" in n:
n = n.replace("meaning of ","")
q= dictionarry(n)
return q
elif 'tell me about' in n:
n = n.replace('tell me about ', '')
q = wikip(n)
return q
elif 'throw a dice' or 'roll a dice' in n:
q = throw()
return q
elif 'what is the time' in n:
now = dt.datetime.now()
real_time = now.strftime("%I:%M %p")
return "It's"+real_time
elif 'what is the date' in n:
now = dt.datetime.now()
real_time = now.strftime("%d-%m-%Y")
return "today is "+real_time
elif 'toss a coin' in n:
q = toss()
return q
else:
q = extras_spam(n)
return q
def main_call(n):
n = n.lower()
return search_for_n(n)