-
-
Save renankof/759dec6014ec16060cc836abc041bd30 to your computer and use it in GitHub Desktop.
Slack messages from CRON
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"token":"xxxxxxxxxx", | |
"subdomain":"subdomain", | |
"username":"Eventbot", | |
"text":"<!everyone> here is an important link: <https://modest.com/|modest.com>", | |
"channel":"#general", | |
"icon": ":ghost:" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from datetime import datetime | |
import json | |
import urllib, hashlib | |
import sys | |
""" | |
Send a message to slack at a certain cron'd time based on a config.json | |
""" | |
config = sys.argv[1] | |
json_data=open(config) | |
config_data = json.load(json_data) | |
today = datetime.now() | |
if today.weekday() <=4: | |
url = "https://"+config_data['subdomain']+".slack.com/services/hooks/incoming-webhook?token="+config_data['token'] | |
payload={"channel": config_data['channel'], "username": config_data['username'], "text": config_data['text'], "icon_emoji": config_data['icon']} | |
r = requests.post(url, data=json.dumps(payload)) | |
print r.content |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment