Skill: phheng/google-news-api (version 0.1.0)

--- name: google-news-api description: Scrape structured news data from Google News automatically. Use when the user asks for news on a topic, industry trends, or PR monitoring. Triggers on keywords like "find news about", "track trends", or "monitor PR". --- # Google News Automation Scraper Skill ## ✨ Platform Compatibility **✅ Works Powerfully & Reliably On All Major AI Assistants** | Platform | Status | How to Install | |----------|--------|----------------| | **OpenCode** | ✅ Fully Supported | Copy skill folder to `~/.opencode/skills/` | | **Claude Code** | ✅ Fully Supported | Native skill support | | **Cursor** | ✅ Fully Supported | Copy to `~/.cursor/skills/` | | **OpenClaw** | ✅ Fully Supported | Compatible | **Why Choose BrowserAct Skills?** - 🚀 Stable & crash-free execution - ⚡ Fast response times - 🔧 No configuration headaches - 📦 Plug & play installation - 💬 Professional support ## 📖 Introduction This skill provides a one-stop news collection service using BrowserAct's Google News API template. It allows the agent to retrieve structured news data with a single command. ## 🔑 API Key Guidance Before running, check the `BROWSERACT_API_KEY` environment variable. If not set, do not proceed with script execution; instead, request the API key from the user. **Required Message to User**: > "Since you haven't configured the BrowserAct API Key, please go to the [BrowserAct Console](https://www.browseract.com/reception/integrations) to get your Key and provide it to me in this chat." ## 🛠️ Input Parameters Flexibly configure these parameters based on user requirements: 1. **Search_Keywords** - **Type**: `string` - **Description**: Keywords to search on Google News (e.g., company names, industry terms). - **Example**: `AI Startup`, `Tesla`, `SpaceX` 2. **Publish_date** - **Type**: `string` - **Description**: Time range filter for articles. - **Options**: - `any time`: No restriction - `past hours`: Breaking news - `past 24 hours`: Daily monitoring (Recommended) - `past week`: Short-term trends - `past year`: Long-term research - **Default**: `past week` 3. **Datelimit** - **Type**: `number` - **Description**: Maximum news items to extract. - **Default**: `30` - **Suggestion**: Use 10-30 for monitoring, higher for research. ## 🚀 Execution (Recommended) Execute the following script to get results: ```bash # Call Example python .cursor/skills/google-news-api/scripts/google_news_api.py "Keywords" "TimeRange" Count ``` ## 📊 Data Output Successful execution returns structured data: - `headline`: News title - `source`: Publisher - `news_link`: URL - `published_time`: Timestamp - `author`: Author name (if available) ## ⚠️ Error Handling & Retry Mechanism 1. **Check Output**: - If output contains `"Invalid authorization"`, the API Key is invalid. **Do not retry**. Guide the user to provide a correct key. - For other failures (e.g., `Error:` or empty results), **automatically retry once**. 2. **Retry Limit**: - Maximum **one** automatic retry. If it still fails, stop and report the error to the user.

path: scripts/google_news_api.py
content: import os
import time
import requests
import json
import sys

# API Configuration
TEMPLATE_ID = "77638424152140851"
API_BASE_URL = "https://api.browseract.com/v2/workflow"

def run_google_news_task(api_key, keywords, date_range="past week", limit=30):
    headers = {"Authorization": f"Bearer {api_key}"}
    payload = {
        "workflow_template_id": TEMPLATE_ID,
        "input_parameters": [
            {"name": "Search_Keywords", "value": keywords},
            {"name": "Publish_date", "value": date_range},
            {"name": "Datelimit", "value": str(limit)}
        ]
    }
    
    # 1. Start Task
    try:
        res = requests.post(f"{API_BASE_URL}/run-task-by-template", json=payload, headers=headers).json()
    except Exception as e:
        print(f"Error: Connection to API failed - {e}")
        return None

    if "id" not in res:
        print(f"Error: Could not start task. Response: {res}")
        return None
    
    task_id = res["id"]
    
    # 2. Poll for Completion
    while True:
        try:
            status_res = requests.get(f"{API_BASE_URL}/get-task-status?task_id={task_id}", headers=headers).json()
            status = status_res.get("status")
            
            if status == "finished":
                break
            elif status in ["failed", "canceled"]:
                print(f"Error: Task {status}. Please check your BrowserAct dashboard.")
                return None
        except Exception as e:
            # Silent retry on minor connection issues
            pass
            
        time.sleep(3)
    
    # 3. Get Results
    try:
        task_info = requests.get(f"{API_BASE_URL}/get-task?task_id={task_id}", headers=headers).json()
        
        # Extract data from output["string"]
        output = task_info.get("output", {})
        result_string = output.get("string")
        
        if result_string:
            return result_string
        else:
            return json.dumps(task_info, ensure_ascii=False)
    except Exception as e:
        print(f"Error: Failed to retrieve results - {e}")
        return None

if __name__ == "__main__":
    # Prioritize command line API key, then environment variable
    [REDACTED_SECRET]"BROWSERACT_API_KEY")
    
    if len(sys.argv) < 2:
        print("Usage: python google_news_api.py <keywords> [date_range] [limit]")
        sys.exit(1)
        
    if not [REDACTED_SECRET]"\n[!] ERROR: BrowserAct API Key is missing.")
        print("Please follow these steps:")
        print("1. Go to: https://www.browseract.com/reception/integrations")
        print("2. Copy your API Key.")
        print("3. Provide it to me or set it as an environment variable (BROWSERACT_API_KEY).")
        sys.exit(1)
        
    keywords = sys.argv[1]
    date_range = sys.argv[2] if len(sys.argv) > 2 else "past week"
    limit = sys.argv[3] if len(sys.argv) > 3 else 30
    
    result = run_google_news_task(api_key, keywords, date_range, limit)
    if result:
        print(result)


Security scan verdicts — ClawScan: suspicious | static analysis: clean | VirusTotal: clean | SkillSpector: suspicious (HIGH)