slackbot.py 文件源码

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

项目:mccelections 作者: mcclatchy 项目源码 文件源码
def slackbot(text):
    """
    Posts messages to Slack channel based on environment
    """

    slack = Slacker(SLACK_TOKEN)
    username = "electionsbot"
    icon_url = "https://c1.staticflickr.com/6/5667/20571587160_92070a9546_b.jpg"
    # icon_url = "https://pixabay.com/static/uploads/photo/2013/07/13/13/41/robot-161368_960_720.png"

    ## set channel based on the environment: local, test, prod
    if mccelectionsenv == "local":
        channel = "#electionserverlocal"
    elif mccelectionsenv == "test":
        channel = "#electionservertest"
    elif mccelectionsenv == "prod":
        channel = "#electionserverprod"

    ## uses try statement in order to avoid requests package error:
        # Max retries exceeded with url
    try:
        slack.chat.post_message(channel, text, username=username, link_names=True, icon_url=icon_url)

        # return "Messaged posted: %s" % (text)

    except:
        print "WARNING: An error occured when trying to send the text to Slack."

    ## outputs to command line so you can follow along/log there, especially when working locally
    print text
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号