#!/usr/bin/python # Copyright 2015 (c) Anna Schumaker. # import slack import sys from email.parser import Parser headers = Parser().parsestr(sys.stdin.read()) if headers['from'] != "Anna Schumaker ": sys.exit(1) # Determine which channel to post to chan_id = headers["X-Slack-Channel"] channel = None for c in slack.channels.list(): if c.id() == chan_id: channel = c break if channel == None: sys.exit(1) lines = headers.get_payload().strip().split("\n") for i in range(len(lines)): if len(lines[i]) == 0: continue if lines[i][0] == ">": break lines = lines[0:i-1] text = ' '.join(lines).strip() channel.post(text)