-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWikiBot.py
More file actions
65 lines (61 loc) · 3.09 KB
/
Copy pathWikiBot.py
File metadata and controls
65 lines (61 loc) · 3.09 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
import time
import json
import wikipedia
import pyowm
from slackclient import SlackClient
owm = pyowm.OWM('') # replace with your OWM key
token = '' # replace with your slack token
sc = SlackClient(token)
print sc.api_call("api.test")
print sc.api_call("auth.test")
print sc.api_call("chat.postMessage",
username='4970WBot',
as_user='false',
icon_emoji=':bowtie:',
channel="C0JT331L0",
text="Hello World!")
if sc.rtm_connect():
while True:
time.sleep(1);
new_evts = sc.rtm_read()
for evt in new_evts:
print(evt)
if "type" in evt:
if evt["type"] == "message" and "text" in evt:
message=evt["text"]
if "wikiBot" in message[ :8]:
try:
sc.api_call("chat.postMessage",
username='WikiBot',
as_user='false',
icon_emoji=':bowtie:',
channel=evt["channel"],
text=wikipedia.summary(message[7:]).encode('utf-8'))
except:
sc.api_call("chat.postMessage",
username='WikiBot',
as_user='false',
icon_emoji=':bowtie:',
channel=evt["channel"],
text="Hmm, I couldn't find that, try another term...")
if "weatherBot" in message [:11]:
try:
weather = owm.weather_at_place('Minneapolis,us').get_weather(); #replace with desired city
sc.api_call("chat.postMessage",
username='WeatherBot',
as_user='false',
icon_emoji=':cloud:',
channel=evt["channel"],
text= "*Weather in Minneapolis* \n" +
"*Temperature:* " +
str(weather.get_temperature('fahrenheit')['temp']) + "F\n" +
"*Humidity:* " +
str(weather.get_humidity()) + "%\n" +
"*Status:* " + str(weather.get_detailed_status()))
except:
sc.api_call("chat.postMessage",
username='WeatherBot',
as_user='false',
icon_emoji=':cloud:',
channel=evt["channel"],
text= "I cannot retrieve the weather for some reason :( I'm sorry I have failed you...")