From a2647bba5614bc2b8f0a30270d99b210712d6087 Mon Sep 17 00:00:00 2001 From: Charles Date: Wed, 6 Apr 2022 17:50:56 +0800 Subject: [PATCH] perf: check seesion timeout --- cnblogs_downloader.py | 5 +++++ readme.md | 17 +++++++++-------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/cnblogs_downloader.py b/cnblogs_downloader.py index eb93c00..dc01f21 100644 --- a/cnblogs_downloader.py +++ b/cnblogs_downloader.py @@ -1,6 +1,7 @@ import json import os import re +import sys import threading from datetime import datetime @@ -44,6 +45,10 @@ def __init__(self, cnblogs_cookie, workdir, download_img=False): "Referer": "https://i.cnblogs.com/", "Cookie": rf".Cnblogs.AspNetCore.Cookies={cnblogs_cookie}"} self._category = api.get_category_list(self._http_headers) + errors = self._category.get("errors1") + if errors is not None and errors[0] == "Unauthorized": + print("Cookie 已过期,请重新配置Cookie") + sys.exit() flag_path = rf"{workdir}\{self._FLAG_FILE_NAME}" if os.path.isfile(flag_path): diff --git a/readme.md b/readme.md index 3a9491e..6d79cc5 100644 --- a/readme.md +++ b/readme.md @@ -18,7 +18,7 @@ -# Table of Contents +## Table of Contents - [Usage](#usage) - [Configuration](#configuration) @@ -30,9 +30,9 @@ - [Links](#links) -# Usage +## Usage -## Configuration +### Configuration 运行前需要配置`config.ini`: @@ -40,13 +40,14 @@ 2. 打开浏览器登录博客园后台,登录时勾选"记住我" 3. 登录后浏览器按F12,找到Cookie,拷贝`.Cnblogs.AspNetCore.Cookies`的值到`config.ini`中 + 4. 其余选项按需填写,文件需以UTF-8编码保存 开启离线后,随笔中的图片链接会被替换自动为本地图片的链接 -## Dependencies +### Dependencies 运行`pip install`前需关闭系统全局代理 @@ -56,7 +57,7 @@ pip install httpx -## Start +### Start 配置好程序并安装好httpx依赖后,命令行运行: @@ -72,7 +73,7 @@ python main.py -## Features +### Features 下载的文件名为随笔标题,分类和标题中的特殊字符`\/:*?"<>|`会被空格代替,文件编码为UTF-8 @@ -98,7 +99,7 @@ python main.py -# For Developer +## For Developer 博客园公开的api文档:https://api.cnblogs.com/help @@ -139,7 +140,7 @@ python main.py -## Document +### Document 本项目API文档:[**Document**](https://charles94jp.github.io/cnblogs-blogger-downloader)