-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhackathon tba.py
More file actions
241 lines (222 loc) · 15.1 KB
/
hackathon tba.py
File metadata and controls
241 lines (222 loc) · 15.1 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
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
from tkinter import *
import random
import wikipedia
import os
import wikipedia.exceptions
import requests
import datetime
import webbrowser
import time
global b
b=100
class TBAClass:
def tBA(self, win, window, name, city):
bgColor = "#163A54"
#win = Tk()
window.title("PaiBot")
window.iconbitmap("PaiBot.ico")
b= 80
window.geometry("480x720")
window.resizable(False, False)
win.config(bg=bgColor)
global botReplyLen, wiki, message
botReplyLen=0
def mainPage():
from MainLayoutClass import MainLayout
frame= Frame(window, width=480,height=720)
frame.pack(fill="both", expand=True)
canvas.pack_forget()
frame1.place_forget()
textbox.place_forget()
btn2.place_forget()
backbtn.place_forget()
mainFrame = MainLayout()
mainFrame.callMain(win, window, name, city)
def bot(self):
global b
try:
input1 = str(textbox.get())
sender(input1)
input1=input1.lower()
def get_time():
time = datetime.datetime.now().time()
receiver("The current Time is: \n"+ str(time))
def get_date():
date = datetime.datetime.now()
receiver("The current date is \n"+ str(date))
greetingsuser = ['hey there', 'hello', 'hi', 'hey', 'hola', 'namaste', 'sasriyakal']
greetingsreply = ['Hey There', 'Hello', 'Hi', 'Hola, How are you?', 'Hey', 'Hola', 'Namaste', 'Sasriyakal']
question = ['how are you', 'How are you doing?','how Are You','what\'s up?', 'what\'s up?']
responses = ["I'm fine", "I'm cool like the moon", "I'm doing great", "I am raising the Stars ☺"]
ownerques = ['who made you?', 'who made you', 'who created you', 'who created you?']
ownerans = ['I was created by Pai Programmers ', 'Pai Programmers', 'A group of super Intelligent kidos']
timevar = ['what time is it', 'what is the time', 'time']
date1 = ['what date is it', 'what is the date', 'date']
aboutme = ['who are you', 'what is your name']
cmd1 = ['open browser', 'open google']
jokesquery = ['tell a joke', 'tell me a joke', 'say something funny', 'tell something funny']
jokes = ['Can a kangaroo jump higher than a house? Of course, a house doesn’t jump at all.', 'My dog used to chase people on a bike a lot. It got so bad, finally I had to take his bike away.', 'Doctor: Im sorry but you suffer from a terminal illness and have only 10 to live.Patient: What do you mean, 10? 10 what? Months? Weeks?!"Doctor: Nine.']
cmd4 = ['open youtube', 'i want to watch a video']
cmd6 = ['exit','close','goodbye', 'nothing','bye']
cmd7 = ['what is your color', 'what is your colour', 'your color', 'your color?']
colrep = ['Right now its rainbow', 'Right now its transparent', 'Right now its non chromatic']
cmd8 = ['what is you favourite colour', 'what is your favourite color']
cmd9 = ['thank you']
cmd10 = ['do you know me','tell me about me','do you know me','who am i']
cmd11 = ['who is sumit','who is sumit?','who is deepak','who is deepak?']
repfr9 = ['You\'re welcome ☻', 'Glad You like it ♥']
while True:
if input1.lower() in greetingsuser:
random_greeting=random.choice(greetingsreply)
receiver(random_greeting+", I am PaiBot, How may I assist You?")
break
elif input1.lower() in question:
receiver('I am fine')
break
elif "calculate" in input1.lower():
subs = input1[10:]
receiver("Answer is :\n"+str(eval(subs)))
break
elif input1 in ownerques:
reply = random.choice(ownerans)
receiver(reply)
break
elif input1 in cmd9:
receiver(random.choice(repfr9))
break
elif input1 in cmd7:
mycolor = random.choice(colrep)+'\nIt keeps changing every micro second'
receiver(mycolor)
break
elif input1 in cmd8:
mycolor = random.choice(colrep)+'\nIt keeps changing every micro second'
receiver(mycolor)
break
elif "temperature" in input1 :
temp = input1.split()
if len(temp)==5:
url = "http://api.openweathermap.org/data/2.5/weather?q="+temp[4]+"&units=metric&APPID=47657b66139fc2cb733e7566ec239fd1"
data = requests.get(url).json()
receiver("Current Temperature of "+temp[4]+" is "+str(data['main']['temp'])+"°C")
elif len(temp)==6:
url = "http://api.openweathermap.org/data/2.5/weather?q="+temp[5]+"&units=metric&APPID=47657b66139fc2cb733e7566ec239fd1"
data = requests.get(url).json()
receiver("Current Temperature of "+temp[5]+" is "+str(data['main']['temp'])+"°C")
elif len(temp)==3:
url = "http://api.openweathermap.org/data/2.5/weather?q="+temp[2]+"&units=metric&APPID=47657b66139fc2cb733e7566ec239fd1"
data = requests.get(url).json()
receiver("Current Temperature of "+temp[2]+" is "+str(data['main']['temp'])+"°C")
else :
receiver("Data is OFF")
break
elif input1 in aboutme:
receiver('I am PaiBot, I am your Personal Assistant')
break
elif input1 in cmd4:
webbrowser.open('www.youtube.com')
break
elif input1 in cmd6:
print('see you later')
exit()
break
elif input1 in cmd10:
print("You are my owner and I glad to help you")
break
elif input1 in cmd11:
sumit="He is one of My Developer. They both are Intelligent"
receiver(sumit)
break
elif input1 in timevar:
get_time()
break
elif input1 in date1:
get_date()
break
elif input1 in cmd1:
receiver('Openning......')
webbrowser.open('www.google.com')
receiver('Done ☺')
break
elif input1 in jokesquery:
joker = random.choice(jokes)
receiver(joker)
break
elif "about" in input1 :
about1 = input1.split()
global wiki
if len(about1)==4:
strs = str(wikipedia.summary(about1[3]))
wiki = wikipedia.page(about1[3]).url
i = strs.index('.')
receiver(strs[:i+1])
moreAbout(wiki)
break
elif "open" in input1.lower():
os.system(input1.split()[1])
break
elif "go to" in input1.lower():
webbrowser.open(input1[6:])
receiver("Done ☻ ")
break
else:
receiver("Sorry, I don't know that. But I am still Learning and Improving ☻")
break
except ZeroDivisionError as e:
receiver(str(e))
except wikipedia.exceptions.DisambiguationError as e :
receiver("Too many results")
except wikipedia.exceptions.PageError as e:
receiver("No details found kindly check Spellings in input")
except requests.exceptions.ConnectionError as e:
receiver("Internet is not connected")
def moreAbout(url):
global b
button1 = Button(win, text = "Click Here For More", command = lambda:openUrl(url), anchor = W, bg="white")
button1.configure(width = 20, height=2, activebackground = "white", relief = FLAT, justify=CENTER, font=("Yatra One",15))
canvas.create_window(50, b, anchor=NW, win=button1)
b+=button1.winfo_reqheight()+30
def openUrl(self):
if(str(wiki)==""):
receiver("No URL Found")
else:
webbrowser.open(wiki)
def receiver(botReply):
global b, message
message = Message(canvas,text=botReply,width=350, font=("Yatra One",15), bg="white", fg="#163A54")
canvas.create_window(50,b,win=message,anchor=NW)
b = b+message.winfo_reqheight()+10
onFrameConfigure(canvas)
canvas.yview_moveto(1.0)
message.bind('<Button-1>', openUrl)
def sender(texts):
textinput.set("")
global b
global message
message = Message(canvas,text=texts,width=350,font=("Yatra One",15),bg="green", fg="white")
canvas.create_window(512,b,win=message,anchor=NE)
b = b+message.winfo_reqheight()+10
onFrameConfigure(canvas)
canvas.yview_moveto(1.0)
frame1=Frame(win,width=460,height=720,bg=bgColor)
frame1.place(x=0,y=0)
canvas=Canvas(frame1,bg=bgColor, width=480,height=680, bd=0, relief='ridge', highlightthickness=0)
vbar=Scrollbar(canvas,orient=VERTICAL,elementborderwidth=-3)
vbar.pack(side=RIGHT,fill=Y)
vbar.config(command=canvas.yview)
canvas.config(yscrollcommand=vbar.set)
def onFrameConfigure(canvas):
canvas.configure(scrollregion=canvas.bbox("all"))
window.bind("<Configure>", lambda event, canvas=canvas: onFrameConfigure(canvas))
canvas.pack(side=LEFT,expand=True,fill=BOTH)
textinput=StringVar()
textbox=Entry(win, width=27,font=("Yatra One", 19), bg=bgColor, fg="#FFFFFF", textvariable=textinput)
textbox.place(x=40,y=680)
textbox.bind('<Return>',bot)
sendphoto = PhotoImage(file="sendButton.png")
btn2=Button(win, command=lambda:bot("Hello"), image=sendphoto, relief = FLAT, bg=bgColor, activebackground=bgColor, bd=0)
btn2.place(x=450,y=685)
back=PhotoImage(file="Logo/back.png")
backbtn = Button(win, text="Back", image=back, font=("Yatra One",10), relief = FLAT, activebackground="#163A54", bd=0, bg="#163A54", command=mainPage)
backbtn.image=back
backbtn.place(x=0,y=680)
win.mainloop()