MCPcopy
hub / github.com/Sophomoresty/gemini-web2api / load_cookie

Function load_cookie

gemini_web2api/gemini.py:48–71  ·  view source on GitHub ↗

Load cookie from file with mtime-based caching.

()

Source from the content-addressed store, hash-verified

46
47
48def load_cookie() -> tuple:
49 """Load cookie from file with mtime-based caching."""
50 cookie_file = CONFIG.get("cookie_file")
51 if not cookie_file or not os.path.exists(cookie_file):
52 return "", None
53 try:
54 mtime = os.path.getmtime(cookie_file)
55 if mtime == _cookie_cache["mtime"] and _cookie_cache["str"]:
56 return _cookie_cache["str"], _cookie_cache["sapisid"]
57 with open(cookie_file, "r") as f:
58 content = f.read().strip()
59 if content.startswith("{"):
60 data = json.loads(content)
61 cookie_str = data.get("cookie", "")
62 sapisid = data.get("sapisid", "")
63 else:
64 cookie_str = content
65 pairs = dict(p.split("=", 1) for p in cookie_str.split("; ") if "=" in p)
66 sapisid = pairs.get("SAPISID", "")
67 _cookie_cache.update({"str": cookie_str, "sapisid": sapisid or None, "mtime": mtime})
68 return cookie_str, sapisid if sapisid else None
69 except Exception as e:
70 log(f"Cookie load error: {e}")
71 return _cookie_cache["str"], _cookie_cache["sapisid"]
72
73
74def make_sapisidhash(sapisid: str) -> str:

Callers 3

_build_headersFunction · 0.70
_get_page_tokensFunction · 0.70
upload_imageFunction · 0.70

Calls 1

logFunction · 0.70

Tested by

no test coverage detected