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

Function _extract_texts_from_line

gemini_web2api/gemini.py:159–179  ·  view source on GitHub ↗

Parse a single wrb.fr line and return list of text strings found.

(line: str)

Source from the content-addressed store, hash-verified

157
158
159def _extract_texts_from_line(line: str) -> list:
160 """Parse a single wrb.fr line and return list of text strings found."""
161 if '"wrb.fr"' not in line or len(line) < 200:
162 return []
163 try:
164 arr = json.loads(line)
165 inner_str = arr[0][2]
166 if not inner_str or len(inner_str) < 50:
167 return []
168 inner = json.loads(inner_str)
169 if not (isinstance(inner, list) and len(inner) > 4 and inner[4]):
170 return []
171 texts = []
172 for part in inner[4]:
173 if isinstance(part, list) and len(part) > 1 and part[1] and isinstance(part[1], list):
174 for t in part[1]:
175 if isinstance(t, str) and t:
176 texts.append(t)
177 return texts
178 except (json.JSONDecodeError, IndexError, TypeError):
179 return []
180
181
182def extract_response_text(raw: str) -> str:

Callers 2

extract_response_textFunction · 0.85
generate_streamFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected