Created
February 27, 2017 13:33
-
-
Save zyouyowa/18403983df9a0f5aef399dfb75638bc0 to your computer and use it in GitHub Desktop.
Slack APIのfiles.uploadで画像を投稿するやつ
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
# -*- coding: utf-8 -*- | |
import requests | |
url = 'https://slack.com/api/' | |
token = 'Slack Bot API Token' | |
def upload(filename, image, channels, filetype='jpg'): | |
joind_channels = ','.join(channels) | |
arguments = { | |
'token': token, | |
'title': filename, | |
'channels': joind_channels | |
} | |
res = requests.post(url + 'files.upload', params=arguments, files={'file':image}) | |
print(res.json()) | |
if __name__ == '__main__': | |
with open('mazaiosamu.jpg', 'rb') as file: | |
upload('mazaiosamu.jpg', file.read(), ['test'], 'jpg') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment