This repository has been archived on 2026-10-23. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
tannleichen/slackorator.py

45 lines
1.0 KiB
Python
Executable File

#!/usr/bin/env python
#coding: utf-8
import ConfigParser
import json
import logging
import re
import requests
import sys
"""
hello this is documentation
"""
__version__ = "0.1"
def post_confession(text):
template = {
'channel': '#tannlegen',
'username': 'Tannlegen',
'icon_emoji': ':beers:'
}
configname = "slackorator.cfg"
cfg = ConfigParser.RawConfigParser()
cfg.read(configname)
headers = {'content-type': 'application/json'}
hook = cfg.get("stuff", "hook")
# Return if text only contains whitespace
if re.search(r'\S', text) is None:
logging.info("Confession only containing whitespace. Abort")
return
logging.info("Attempting to post confession to slack")
try:
r = requests.post(hook,
data=json.dumps(dict({'text': text}, **template)),
headers=headers)
r.raise_for_status()
except Exception, e:
logging.error("Failed to post confession to slack")
logging.exception(e)
pass