@danhachuel/thunderbolt 0.6.39 → 0.6.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -152,6 +152,17 @@ def _fetch_web_profile_user(username: str) -> dict[str, Any] | None:
152
152
  merged[key] = value
153
153
  return merged
154
154
 
155
+ def extract_user(payload: Any) -> Mapping[str, Any] | None:
156
+ if not isinstance(payload, Mapping):
157
+ return None
158
+ candidates = [
159
+ payload.get('user'),
160
+ (payload.get('data') or {}).get('user') if isinstance(payload.get('data'), Mapping) else None,
161
+ (payload.get('graphql') or {}).get('user') if isinstance(payload.get('graphql'), Mapping) else None,
162
+ (payload.get('data') or {}).get('profile') if isinstance(payload.get('data'), Mapping) else None,
163
+ ]
164
+ return next((candidate for candidate in candidates if isinstance(candidate, Mapping)), None)
165
+
155
166
  request_headers = [
156
167
  headers,
157
168
  {**headers, 'User-Agent': 'Instagram 390.0.0.0.50 Android', 'Accept': 'application/json, text/plain, */*'},
@@ -169,7 +180,7 @@ def _fetch_web_profile_user(username: str) -> dict[str, Any] | None:
169
180
  if best_user:
170
181
  return best_user
171
182
  continue
172
- user = ((payload.get('data') or {}).get('user') if isinstance(payload, dict) else None)
183
+ user = extract_user(payload)
173
184
  if isinstance(user, dict):
174
185
  best_user = merge_profile(best_user, user)
175
186
  if profile_quality(best_user) >= 4:
@@ -189,7 +200,7 @@ def _fetch_web_profile_user(username: str) -> dict[str, Any] | None:
189
200
  check=False,
190
201
  )
191
202
  payload = json.loads(completed.stdout) if completed.returncode == 0 and completed.stdout else None
192
- user = ((payload.get('data') or {}).get('user') if isinstance(payload, dict) else None)
203
+ user = extract_user(payload)
193
204
  if isinstance(user, dict):
194
205
  best_user = merge_profile(best_user, user)
195
206
  if profile_quality(best_user) >= 4:
@@ -215,7 +226,7 @@ def _fetch_web_profile_user(username: str) -> dict[str, Any] | None:
215
226
  if response is None or response.status >= 400:
216
227
  continue
217
228
  payload = json.loads(page.locator('body').inner_text(timeout=5000))
218
- user = ((payload.get('data') or {}).get('user') if isinstance(payload, dict) else None)
229
+ user = extract_user(payload)
219
230
  if isinstance(user, dict):
220
231
  best_user = merge_profile(best_user, user)
221
232
  if profile_quality(best_user) >= 4:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danhachuel/thunderbolt",
3
- "version": "0.6.39",
3
+ "version": "0.6.40",
4
4
  "description": "Thunderbolt — interface local para operação de canais faceless e motor MoneyPrinterTurbo",
5
5
  "license": "MIT",
6
6
  "main": "scripts/cli.mjs",