2017-04-21 87 views
0

如何將由pyplot創建的圖像發送到Slack頻道?在本地保存它,然後嘗試將本地文件傳遞爲image_url不起作用發佈pyplot圖片到Slack

import matplotlib.pyplot as pyplot 
from slacker import Slacker 

slack = Slacker("supersecretkey") 
fig, ax = pyplot.subplots(figsize=(8,6)) 

ax.plot([1,2], [4,2]) 
fig.savefig("C:\file.png") 

attachments = [{"title": "test", 
       "image_url": "C:\file.png"}] 
slack.chat.post_message("@mathias", "TEXT_TEST", "TEST", attachments=attachments) 

難道不幸的是沒有工作。

我還試圖上載文件

slack.files.upload("C:\file.png") 

並在attachment使用的permalink_public(從上述命令的執行結果),但沒有成功:

empty message :(

我怎樣才能解決這沒有太多的麻煩(例如上傳到外部圖像主機)?

回答

0

訣竅是確實使用slack.files.upload,但立即把它放在一個渠道:

slack.files.upload("C:\file.png", channels="@slackbot")