-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
83 lines (69 loc) · 2.41 KB
/
app.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
import reqRes
import re
import webbrowser
import subprocess
import datetime
from pyowm import OWM
def assistant(command):
# conversation
if 'hello' in command:
t = datetime.datetime.now()
if t.hour < 12:
greet = "Good Morning"
elif t.hour > 12 and t.hour < 18:
greet = "Good Afternoon"
else:
greet = "Good Evening"
reqRes.botResponse("{}! What can I do for you?".format(greet))
elif 'shutdown' in command:
reqRes.botResponse("Enjoy your day!")
exit()
# task 1 - Open website
elif "open" in command:
reg_ex = re.search('open (.+)', command)
domain = reg_ex.group(1)
if reg_ex:
url = 'https://www.'+domain
webbrowser.open(url)
reqRes.botResponse("Opening {}".format(domain))
else:
pass
# task 2 - Weather functionality
elif "current weather" in command:
reg_ex = re.search('current weather in (.+)', command)
if reg_ex:
city = reg_ex.group(1)
owm = OWM('043c95bd84b2bbcdcf7404f634788f85')
mgr = owm.weather_manager()
obs = mgr.weather_at_place(city)
w = obs.weather
s = w.status()
t = w.temperature('celsius')
reqRes.botResponse('Current weather in %s is %s. The maximum temperature is %0.2f and the minimum temperature is %0.2f degree celcius' % (city, s, t['temp_max'], t['temp_min']))
elif "time" in command:
t = datetime.datetime.now()
h = t.hour
m = t.minute
s = t.second
res = 'The time is {} hours {} minutes and {} seconds.'.format(h,m,s)
print(res)
reqRes.botResponse(res)
elif "date" in command:
t = datetime.datetime.now()
d = t.day
m = t.month
y = t.year
res = 'Today is {}, {}, {}.'.format(d,m,y)
print(res)
reqRes.botResponse(res)
# TODO: News feed
# TODO: Search
# # task 2 - Launch System Application
# elif 'launch' in command:
# reg_ex = re.search('open (.+)', command)
# appName = reg_ex.group(1)
# if reg_ex:
# subprocess.Popen("open", "-n", "/Applications")
# reqRes.botResponse("Opening {}".format(appName))
# else:
# pass