Created
March 8, 2016 22:57
-
-
Save jbowes/70643df54e78480cc73d to your computer and use it in GitHub Desktop.
Progress in Slack via snippets
This file contains hidden or 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
# coding=utf-8 | |
from __future__ import unicode_literals | |
import datetime | |
import os | |
import time | |
import requests | |
TOKEN = os.environ.get("SLACK_TOKEN") | |
CHANNEL = os.environ.get("SLACK_CHANNEL") | |
done = "█" | |
not_done = " " | |
messages = [ | |
"Selling customer CCs to bad guys", | |
"Deleting user data", | |
"Smashing backups", | |
"Dropping triggers", | |
"Panicking", | |
] | |
def main(): | |
start = datetime.datetime.utcnow() | |
params = { | |
"token": TOKEN, | |
"channels": CHANNEL, | |
"title": ":skull_and_crossbones: " | |
"Destroying Production Database :skull_and_crossbones:", | |
"content": " 0%▕" + not_done * 10 + "▏00:00", | |
} | |
resp = requests.post("https://slack.com/api/files.upload", params=params) | |
file_id = resp.json()["file"]["id"] | |
params["file"] = file_id | |
msg_i = 0 | |
buf = [] | |
for i in range (0, 11): | |
now = datetime.datetime.utcnow() - start | |
elapsed = "%.2d:%.2d" % (now.total_seconds() / 60, | |
now.total_seconds() % 60) | |
bar = "▕" + done * i + not_done * (10 - i) + "▏" | |
params["content"] = " %3d%%" % (i * 10) + bar + elapsed | |
if i % 2 == 0 and msg_i < len(messages): | |
if len(buf) > 0: | |
buf[-1] = "✓ " + buf[-1] | |
buf.append(messages[msg_i]) | |
msg_i += 1 | |
if i == 10: | |
if len(buf) > 0: | |
buf[-1] = "✓ " + buf[-1] | |
buf.append("Done!") | |
if len(buf) > 3: | |
buf = buf [1:] | |
params["content"] += "\n - " + "\n - ".join(buf) | |
requests.post("https://slack.com/api/files.edit", params=params) | |
time.sleep(1) | |
if __name__ == "__main__": | |
main() |
Author
jbowes
commented
Mar 8, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment