Skip to content

Commit

Permalink
修复没有传入cookie时的情况
Browse files Browse the repository at this point in the history
  • Loading branch information
Sving1024 committed Nov 2, 2024
1 parent de009fa commit 2f39bff
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/lgsv/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand All @@ -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():
Expand Down
8 changes: 4 additions & 4 deletions src/lgsv/luogu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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:
"""洛谷题目类"""
Expand Down Expand Up @@ -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"
Expand Down
6 changes: 5 additions & 1 deletion src/lgsv/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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"]
Expand Down

0 comments on commit 2f39bff

Please sign in to comment.