main.py 文件源码

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

项目:flibusta_bot 作者: Kurbezz 项目源码 文件源码
def download(type_, book_id, msg):
    try:
        if type_ in ['fb2', 'epub', 'mobi']:
            r = requests.get(f"http://flibusta.is/b/{book_id}/{type_}")
        else:
            r = requests.get(f"http://flibusta.is/b/{book_id}/download")
    except requests.exceptions.ConnectionError as err:
        telebot.logger.exception(err)
        return None
    if 'text/html' in r.headers['Content-Type']:  # if bot get html file with error message
        try:  # try download file from tor
            if type_ in ['fb2', 'epub', 'mobi']:
                r = requests.get(f"http://flibustahezeous3.onion/b/{book_id}/{type_}",
                                 proxies=config.PROXIES)
            else:
                r = requests.get(f"http://flibustahezeous3.onion/b/{book_id}/download",
                                 proxies=config.PROXIES)
        except requests.exceptions.ConnectionError as err:
            logger.debug(err)
            bot.reply_to(msg, "?????? ??????????? ? ???????! ?????????? ???????.").wait()
            return None
    if 'text/html' in r.headers['Content-Type']:  # send message to user when get
        bot.reply_to(msg, "??????! ?????????? ????? ???? ????? :(").wait()  # html file
        return None
    return r
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号