Skip to content

Instantly share code, notes, and snippets.

@harperreed
Created December 29, 2014 17:33
Show Gist options
  • Save harperreed/c8caaa69b187fd242bf2 to your computer and use it in GitHub Desktop.
Save harperreed/c8caaa69b187fd242bf2 to your computer and use it in GitHub Desktop.
Slack messages from CRON
{
"token":"xxxxxxxxxx",
"subdomain":"subdomain",
"username":"Eventbot",
"text":"<!everyone> here is an important link: <https://modest.com/|modest.com>",
"channel":"#general",
"icon": ":ghost:"
}
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