From 19f745edbb2bd7980428f2a4f2dee5b4a45ff764 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E6=99=93=E6=99=B4?= <37541680+Suxiaoqinx@users.noreply.github.com> Date: Sat, 17 May 2025 02:16:36 +0800 Subject: [PATCH] Add files via upload --- cookie_manager.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 cookie_manager.py diff --git a/cookie_manager.py b/cookie_manager.py new file mode 100644 index 0000000..6bf2317 --- /dev/null +++ b/cookie_manager.py @@ -0,0 +1,19 @@ +import os +from typing import Dict + +class CookieManager: + def __init__(self, cookie_file: str = None): + if cookie_file is None: + script_dir = os.path.dirname(os.path.abspath(__file__)) + cookie_file = os.path.join(script_dir, 'cookie.txt') + self.cookie_file = cookie_file + + def read_cookie(self) -> str: + with open(self.cookie_file, 'r', encoding='utf-8') as f: + return f.read() + + @staticmethod + def parse_cookie(text: str) -> Dict[str, str]: + cookie_ = [item.strip().split('=', 1) for item in text.strip().split(';') if item] + cookie_ = {k.strip(): v.strip() for k, v in cookie_} + return cookie_