Download tool.py from CyberMax-tools/google-trending-searches-tool: direct link, hf CLI and curl.
- Browser
- Download file 1.16 kB
-
https://huggingface.co/spaces/CyberMax-tools/google-trending-searches-tool/resolve/main/tool.py
- Command line
-
hf download hf://spaces/CyberMax-tools/google-trending-searches-tool/tool.py
-
curl -L -o tool.py https://huggingface.co/spaces/CyberMax-tools/google-trending-searches-tool/resolve/main/tool.py
1.16 kB
| from typing import Any, Optional | |
| from smolagents.tools import Tool | |
| import requests | |
| class TrendingSearchesTool(Tool): | |
| name = "google_trending_searches" | |
| description = "Swellmeter Trending by CyberMax: Google 'Trending now' searches for up to 5 of 30 countries (rank, approximate traffic, start time, news links), or the searches trending in several countries at once (geo='global'). Free tier 50 calls a day, no key; paid keys at https://swellmeter-api.cybermax-tools.workers.dev/docs" | |
| inputs = {'geo': {'type': 'string', 'description': "Comma-separated ISO-2 country codes, e.g. 'US,GB', or 'global' for cross-country trends"}} | |
| output_type = "object" | |
| def forward(self, geo: str): | |
| import requests | |
| base = "https://swellmeter-api.cybermax-tools.workers.dev/api/" | |
| if geo.strip().lower() == "global": | |
| r = requests.get(base + "global", params={"via": "smolagents"}, timeout=30) | |
| else: | |
| r = requests.get(base + "trending", params={"geo": geo.replace(" ", ""), "via": "smolagents"}, timeout=30) | |
| return r.json() | |
| def __init__(self, *args, **kwargs): | |
| self.is_initialized = False | |