Spaces:
Sleeping
Sleeping
meirk-brd
commited on
Commit
·
719bd5b
1
Parent(s):
39bf16d
fix payload
Browse files
tool.py
CHANGED
|
@@ -79,34 +79,39 @@ class BrightDataDatasetTool(Tool):
|
|
| 79 |
num_of_reviews: Optional[str] = None,
|
| 80 |
num_of_comments: Optional[str] = None,
|
| 81 |
) -> str:
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
|
|
|
|
|
|
|
|
|
| 100 |
|
| 101 |
-
|
| 102 |
|
| 103 |
-
try:
|
| 104 |
snapshot_id = self._trigger_snapshot(dataset, payload, api_token)
|
| 105 |
data = self._poll_snapshot(snapshot_id, api_token)
|
| 106 |
return json.dumps(data, indent=2)
|
|
|
|
| 107 |
except requests.exceptions.RequestException as exc:
|
| 108 |
details = exc.response.text if getattr(exc, "response", None) is not None else ""
|
| 109 |
return json.dumps({"error": str(exc), "details": details, "payload": payload, "coerced_url": url})
|
|
|
|
|
|
|
| 110 |
|
| 111 |
def _build_params(
|
| 112 |
self,
|
|
|
|
| 79 |
num_of_reviews: Optional[str] = None,
|
| 80 |
num_of_comments: Optional[str] = None,
|
| 81 |
) -> str:
|
| 82 |
+
try:
|
| 83 |
+
url = self._coerce_url_input(url)
|
| 84 |
+
|
| 85 |
+
api_token = os.getenv("BRIGHT_DATA_API_TOKEN")
|
| 86 |
+
if not api_token:
|
| 87 |
+
raise ValueError("BRIGHT_DATA_API_TOKEN not found in environment variables")
|
| 88 |
+
|
| 89 |
+
if dataset not in self.datasets:
|
| 90 |
+
raise ValueError(
|
| 91 |
+
f"Unknown dataset '{dataset}'. Valid options: {', '.join(sorted(self.datasets.keys()))}"
|
| 92 |
+
)
|
| 93 |
+
|
| 94 |
+
params = self._build_params(
|
| 95 |
+
url=url,
|
| 96 |
+
keyword=keyword,
|
| 97 |
+
first_name=first_name,
|
| 98 |
+
last_name=last_name,
|
| 99 |
+
days_limit=days_limit,
|
| 100 |
+
num_of_reviews=num_of_reviews,
|
| 101 |
+
num_of_comments=num_of_comments,
|
| 102 |
+
)
|
| 103 |
|
| 104 |
+
payload = self._prepare_payload(dataset, params)
|
| 105 |
|
|
|
|
| 106 |
snapshot_id = self._trigger_snapshot(dataset, payload, api_token)
|
| 107 |
data = self._poll_snapshot(snapshot_id, api_token)
|
| 108 |
return json.dumps(data, indent=2)
|
| 109 |
+
|
| 110 |
except requests.exceptions.RequestException as exc:
|
| 111 |
details = exc.response.text if getattr(exc, "response", None) is not None else ""
|
| 112 |
return json.dumps({"error": str(exc), "details": details, "payload": payload, "coerced_url": url})
|
| 113 |
+
except Exception as exc:
|
| 114 |
+
return json.dumps({"error": str(exc)})
|
| 115 |
|
| 116 |
def _build_params(
|
| 117 |
self,
|