crawl_page.py 文件源码

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

项目:GWork 作者: shunk031 项目源码 文件源码
def safe_post_message(slacker, crawler, start_id, post_message, max_retries=3):
    """
    post for my slack channel
    :param slacker.Slacker slacker:
    :param g_crawler.crawler.GCrawler crawler:
    :param int start_id:
    :param str post_message:
    :param int max_retries=3:
    """

    retries = 0

    while True:
        try:
            slacker.chat.post_message("#crawler", "[{}] [ID: {}] {}".format(crawler.__class__.__name__, start_id, post_message))
        except HTTPError as http_err:
            retries += 1
            if retries >= max_retries:
                raise Exception("Too many retries.")

            wait = 2 ** (retries)
            print("[ RETRY ] Waiting {} seconds...".format(wait))
            time.sleep(wait)
        else:
            break
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号