File size: 1,164 Bytes
6305006
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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