Created
February 3, 2021 16:27
-
-
Save manuq/2e9f50cb0da06d1e3ddedc791f185525 to your computer and use it in GitHub Desktop.
Send daily report to Slack.
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
#!/usr/bin/env python3 | |
""" | |
Usage | |
----- | |
Change the channel ID, specify the slackUserToken environment | |
variable, then pipe the report through this script. | |
Available formatting: | |
https://api.slack.com/reference/surfaces/formatting | |
```console | |
$ export slackUserToken='xoxp-your-user-token'; | |
$ cat <<EOF | eos-daily-report | |
> Progress: | |
> • Worked on Foo <https://phabricator.endlessm.com/T31315 | T31315> | |
> • Also worked on Bar. | |
> Next: Continue with Bar. | |
> Impediments: - | |
> EOF | |
``` | |
""" | |
import os | |
import sys | |
import datetime | |
import requests | |
slack_info = { | |
'token': os.environ.get('slackUserToken'), | |
'channel': '#mychannel', | |
'as_user': True, | |
} | |
d = datetime.date.today() | |
s = '*' + d.strftime('%A, %B %d %Y') + '*' | |
s += '\n' + ''.join(sys.stdin.readlines()) | |
r = requests.post('https://slack.com/api/chat.postMessage', dict( | |
{'text': s}, | |
**slack_info, | |
)).json() | |
if not r['ok']: | |
print(f'Error: {r}', file=sys.stderr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment