slack.py 文件源码

python
阅读 30 收藏 0 点赞 0 评论 0

项目:luigi-slack 作者: gerardobort 项目源码 文件源码
def run(self):
        # create one at https://api.slack.com/web#authentication, and set the environment variable
        sc = SlackClient(os.environ["SLACK_CLIENT_TOKEN"])
        channel_id = 0

        # Get Channel Information
        for channel in sc.api_call("channels.list")["channels"]:
            if (channel["name"] == self.channel_name):
                channel_id = channel["id"]

        # Get Channel History
        if (self.last_message_id):
            channel_history_chunk = sc.api_call("channels.history", channel=channel_id, count=1000, latest=self.last_message_id)
        else:
            channel_history_chunk = sc.api_call("channels.history", channel=channel_id, count=1000)

        if (not channel_history_chunk["ok"]):
            raise Exception('Channel not found, or permissions error', 'channel_name=' + self.channel_name)

        channel_history_chunk_last_message = channel_history_chunk["messages"]
        outputdata = channel_history_chunk
        with self.output().open('w') as outfile:
            json.dump(outputdata, outfile, sort_keys=True, indent=4, separators=(',', ': '))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号