diff --git a/src/lgsv/cli.py b/src/lgsv/cli.py index 04ba61e..62a8aad 100644 --- a/src/lgsv/cli.py +++ b/src/lgsv/cli.py @@ -11,7 +11,8 @@ async def main(): """main 函数""" setting.parse_args() # await luogu.fetch_csrf_token() - luogu.headers["Cookie"]=setting.global_config["cookie"] + if setting.global_config["cookie"] is not None: + luogu.headers["Cookie"]=setting.global_config["cookie"] md_src = "" problems = [] trainings = [] @@ -31,7 +32,7 @@ async def main(): tg.create_task(p.fetch_resources()) for p in problems: md_src += p.get_markdown(setting.global_config['order']) - with open(file="out.md", mode="w",encoding="utf-8") as f: + with open(file=setting.global_config["output"], mode="w",encoding="utf-8") as f: f.write(md_src) def run(): diff --git a/src/lgsv/luogu.py b/src/lgsv/luogu.py index 1ca7c44..0a5973d 100644 --- a/src/lgsv/luogu.py +++ b/src/lgsv/luogu.py @@ -24,9 +24,9 @@ } params = {"_contentOnly": ""} - +""" async def fetch_csrf_token(): - """获取csrf token""" + 获取csrf token async with httpx.AsyncClient() as client: response = await client.get( url="https://www.luogu.com.cn", @@ -38,7 +38,7 @@ async def fetch_csrf_token(): csrf_token = soup.find("meta", attrs={"name": "csrf-token"}) headers["x-csrf-token"] = csrf_token.get("content") return headers["x-csrf-token"] - +""" class Problem: """洛谷题目类""" @@ -80,7 +80,7 @@ def part_markdown(self, part): case "translation" | "tr": ret = "## 题目翻译" p = "translation" - if self.data[p] is None: + if str(p) not in self.data: return "" if p != "title": ret += "\n" diff --git a/src/lgsv/setting.py b/src/lgsv/setting.py index 1461110..94ab858 100644 --- a/src/lgsv/setting.py +++ b/src/lgsv/setting.py @@ -39,6 +39,7 @@ arg_parser.add_argument("--order", type=str, help="指定题目部分的顺序") # arg_parser.add_argument("-u","--uid",type=int,help="洛谷uid") arg_parser.add_argument("-c", "--cookie", type=str, help="洛谷cookie") +arg_parser.add_argument("-o","--output",type=str,help="输出 markdown 的位置") def parse_args(): @@ -57,7 +58,10 @@ def parse_args(): # cookies["_uid"]=args["uid"] if args["order"] is not None: global_config["order"] = args["order"].split(",") - + if args["output"] is not None: + global_config["output"]=args["output"] + else: + global_config["output"]="out.md" # if "client_id" in args: # global_config["client_id"]=args["client_id"]