forked from vishwa35/slackbot-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscheduled.py
37 lines (30 loc) · 977 Bytes
/
scheduled.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
import os
import schedule
import time
import logging
from slackclient import SlackClient
logging.basicConfig(level=logging.DEBUG)
def sendMessage(slack_client, msg):
# make the POST request through the python slack client
updateMsg = slack_client.api_call(
"chat.postMessage",
channel='#test',
text=msg
)
# check if the request was a success
if updateMsg['ok'] is not True:
logging.error(updateMsg)
else:
logging.debug(updateMsg)
if __name__ == "__main__":
SLACK_BOT_TOKEN = os.environ['SLACK_BOT_TOKEN']
slack_client = SlackClient(SLACK_BOT_TOKEN)
logging.debug("authorized slack client")
# # For testing
msg = "Good Morning!"
schedule.every(60).seconds.do(lambda: sendMessage(slack_client, msg))
# schedule.every().monday.at("13:15").do(lambda: sendMessage(slack_client, msg))
logging.info("entering loop")
while True:
schedule.run_pending()
time.sleep(5) # sleep for 5 seconds between checks on the scheduler