-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload_slack.py
executable file
·34 lines (26 loc) · 1.08 KB
/
upload_slack.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env python3
"""Upload a file to slack."""
# https://github.com/os/slacker
# https://api.slack.com/methods
import argparse
import os
import six
from slacker import Slacker
def upload_slack(file_upload):
"""Upload a file to slack."""
try:
token = os.environ["SLACK_TOKEN"]
slack = Slacker(token)
# By default, all newly-uploaded files are private and only visible to
# the owner. They become public once they are shared into a public
# channel (which can happen at upload time via the channel's argument).
# obj = slack.files.upload(file_upload, channels='#general')
obj = slack.files.upload(file_upload)
six.print_(obj.successful, obj.body["file"]["channels"], obj.body["file"]["id"])
except KeyError as ex:
six.print_("Environment variable %s not set." % str(ex))
if __name__ == "__main__":
PARSER = argparse.ArgumentParser(description="upload a file to slack")
PARSER.add_argument("-f", "--file", help="file", required=True)
ARGS = vars(PARSER.parse_args())
upload_slack(ARGS["file"])