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

Function load_cookie

gemini_web2api.py:105–126  ·  view source on GitHub ↗

Load cookie from file. Returns (cookie_str, sapisid).

()

Source from the content-addressed store, hash-verified

103
104
105def load_cookie() -> tuple:
106 """Load cookie from file. Returns (cookie_str, sapisid)."""
107 cookie_file = CONFIG.get("cookie_file")
108 if not cookie_file:
109 return "", None
110 if not os.path.exists(cookie_file):
111 return "", None
112 try:
113 with open(cookie_file, "r") as f:
114 content = f.read().strip()
115 if content.startswith("{"):
116 data = json.loads(content)
117 cookie_str = data.get("cookie", "")
118 sapisid = data.get("sapisid", "")
119 else:
120 cookie_str = content
121 pairs = dict(p.split("=", 1) for p in cookie_str.split("; ") if "=" in p)
122 sapisid = pairs.get("SAPISID", "")
123 return cookie_str, sapisid if sapisid else None
124 except Exception as e:
125 log(f"Cookie load error: {e}")
126 return "", None
127
128
129def make_sapisidhash(sapisid: str) -> str:

Callers 2

gemini_stream_generateFunction · 0.70

Calls 1

logFunction · 0.70

Tested by

no test coverage detected