{"id":18655493,"url":"https://github.com/ronknight/google-trends-api-webserver","last_synced_at":"2026-02-14T05:09:10.421Z","repository":{"id":258311970,"uuid":"873788364","full_name":"ronknight/google-trends-api-webserver","owner":"ronknight","description":"🔧 A Python-based script to compare the popularity of multiple keywords using Google Trends data, now with a Flask web interface for easy access and visualization.","archived":false,"fork":false,"pushed_at":"2024-10-16T18:12:40.000Z","size":90,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-09T13:41:49.589Z","etag":null,"topics":["api","flask","google-trends-api","pytrends","webserver"],"latest_commit_sha":null,"homepage":"https://www.pinoyitsolution.com","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ronknight.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"patreon":"PinoyITSolution"}},"created_at":"2024-10-16T18:08:08.000Z","updated_at":"2024-12-30T22:30:41.000Z","dependencies_parsed_at":null,"dependency_job_id":"a342b095-c32e-450d-8e05-08a8a9dd2743","html_url":"https://github.com/ronknight/google-trends-api-webserver","commit_stats":null,"previous_names":["ronknight/google-trends-api-webserver"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/ronknight/google-trends-api-webserver","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ronknight%2Fgoogle-trends-api-webserver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ronknight%2Fgoogle-trends-api-webserver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ronknight%2Fgoogle-trends-api-webserver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ronknight%2Fgoogle-trends-api-webserver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ronknight","download_url":"https://codeload.github.com/ronknight/google-trends-api-webserver/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ronknight%2Fgoogle-trends-api-webserver/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29437371,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-14T03:34:37.767Z","status":"ssl_error","status_checked_at":"2026-02-14T03:34:09.092Z","response_time":53,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","flask","google-trends-api","pytrends","webserver"],"created_at":"2024-11-07T07:19:07.579Z","updated_at":"2026-02-14T05:09:10.398Z","avatar_url":"https://github.com/ronknight.png","language":"Python","funding_links":["https://patreon.com/PinoyITSolution"],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003e📊 \u003ca href=\"https://github.com/ronknight/google-trends\"\u003eGoogle Trends Comparison Script (Flask API with Web Interface)\u003c/a\u003e\u003c/h1\u003e\r\n\r\n\u003ch4 align=\"center\"\u003e🔧 A Python-based script to compare the popularity of multiple keywords using Google Trends data, now with a Flask web interface for easy access and visualization.\u003c/h4\u003e\r\n\r\n\u003cp align=\"center\"\u003e\r\n  \u003ca href=\"#overview\"\u003eOverview\u003c/a\u003e •\r\n  \u003ca href=\"#features\"\u003eFeatures\u003c/a\u003e •\r\n  \u003ca href=\"#prerequisites\"\u003ePrerequisites\u003c/a\u003e •\r\n  \u003ca href=\"#how-to-use\"\u003eHow to Use\u003c/a\u003e •\r\n  \u003ca href=\"#api-endpoints\"\u003eAPI Endpoints\u003c/a\u003e •\r\n  \u003ca href=\"#web-interface\"\u003eWeb Interface\u003c/a\u003e •\r\n  \u003ca href=\"#example-output\"\u003eExample Output\u003c/a\u003e •\r\n  \u003ca href=\"#visualization\"\u003eVisualization\u003c/a\u003e •\r\n  \u003ca href=\"#error-handling\"\u003eError Handling\u003c/a\u003e •\r\n  \u003ca href=\"#license\"\u003eLicense\u003c/a\u003e\r\n\u003c/p\u003e\r\n\r\n## Overview\r\n\r\nThis Python-based script allows you to compare the popularity of two or three keywords over a specified timeframe using Google Trends data. The script fetches interest over time for the provided keywords and visualizes the trends using `matplotlib`. You can now access the comparison tool via a Flask web interface, submit keywords, and display the resulting comparison image directly in your browser.\r\n\r\n## Features\r\n\r\n- Compare the search interest of **2 or 3 keywords** over a custom time period.\r\n- **Supports multiple timeframes**, including the past 7 days, past 12 months, and custom date ranges.\r\n- Outputs a **visual plot** of the trends, saved as a `.png` image.\r\n- Uses the **Google Trends API** (`pytrends`) to fetch real-time or historical trend data.\r\n- Provides a **Flask-based web interface** for easy access and interaction.\r\n- Handles **rate-limiting** with an optional delay between requests to avoid being blocked by Google.\r\n\r\n## Prerequisites\r\n\r\nBefore running the script or Flask API, ensure you have the following Python packages installed:\r\n\r\n- `Flask`\r\n- `Flask-CORS`\r\n- `pytrends`\r\n- `matplotlib`\r\n- `pandas`\r\n\r\nInstall the required packages using:\r\n\r\n```bash\r\npip install Flask Flask-CORS pytrends matplotlib pandas\r\n```\r\n\r\n## How to Use\r\n\r\n### Running the Script via Web Interface\r\n\r\n1. **Run the Flask server** to expose the web interface throughout the network:\r\n\r\n   ```bash\r\n   python app.py\r\n   ```\r\n\r\n2. Open your browser and go to `http://localhost:5000`. You’ll see a web form where you can input the keywords and select a timeframe for comparison.\r\n\r\n3. After submitting the form, the trends comparison plot will be generated and displayed on the results page.\r\n\r\n### Running the Script Directly\r\n\r\n1. **Run the script** by passing at least two required keywords and an optional third keyword. Additionally, you can specify a timeframe.\r\n\r\n2. **Command-line Usage**:\r\n\r\n   ```bash\r\n   python google_trends_compare.py \u003ckeyword1\u003e \u003ckeyword2\u003e [--keyword3 \u003ckeyword3\u003e] [--timeframe \u003ctimeframe\u003e]\r\n   ```\r\n\r\n   - `\u003ckeyword1\u003e`: The first keyword for comparison.\r\n   - `\u003ckeyword2\u003e`: The second keyword for comparison.\r\n   - `--keyword3 \u003ckeyword3\u003e`: (Optional) A third keyword to compare.\r\n   - `--timeframe \u003ctimeframe\u003e`: (Optional) Specify the time range for comparison. Defaults to `today 12-m`.\r\n\r\n3. **Example Commands**:\r\n   \r\n   Compare two keywords (`\"Python\"` and `\"Java\"`) over the last 7 days:\r\n   ```bash\r\n   python google_trends_compare.py \"Python\" \"Java\" --timeframe \"now 7-d\"\r\n   ```\r\n\r\n   Compare three keywords (`\"spiderman\"`, `\"batman\"`, `\"superman\"`) over the last 12 months:\r\n   ```bash\r\n   python google_trends_compare.py \"spiderman\" \"batman\" --keyword3 \"superman\" --timeframe \"today 12-m\"\r\n   ```\r\n\r\n## Web Interface\r\n\r\n### Accessing the Web Interface\r\n\r\n1. **Open a browser** and go to the URL `http://localhost:5000`.\r\n2. **Fill in the form** with two or three keywords and select a timeframe from the dropdown menu.\r\n3. Submit the form, and the **Google Trends comparison plot** will be generated and displayed on the results page.\r\n\r\n### Example Form Inputs:\r\n\r\n- **Keyword 1**: `Python`\r\n- **Keyword 2**: `Java`\r\n- **Keyword 3 (Optional)**: `JavaScript`\r\n- **Timeframe**: `today 12-m`\r\n\r\n### Example Output:\r\n\r\nThe script generates a comparison plot of the search trends, such as the one below:\r\n\r\n![Example Plot](static/google_trends_comparison.png)\r\n\r\n## API Endpoints\r\n\r\n### `/compare`\r\n\r\n- **Method**: `POST`\r\n- **Description**: Compare the search trends of two or three keywords over a specified timeframe and receive a plot as the output.\r\n\r\n- **Request Body**:\r\n  - `keywords`: A list of two or three keywords to compare.\r\n  - `timeframe`: (Optional) The time range for comparison. Defaults to `today 12-m`.\r\n\r\n  Example `POST` request:\r\n\r\n  ```json\r\n  {\r\n    \"keywords\": [\"Python\", \"Java\", \"JavaScript\"],\r\n    \"timeframe\": \"today 12-m\"\r\n  }\r\n  ```\r\n\r\n- **Response**:\r\n\r\n  ```json\r\n  {\r\n    \"message\": \"Comparison successful\",\r\n    \"image\": \"google_trends_comparison.png\"\r\n  }\r\n  ```\r\n\r\n- **Example Request** using `curl`:\r\n\r\n  ```bash\r\n  curl -X POST http://localhost:5000/compare \\\r\n       -H \"Content-Type: application/json\" \\\r\n       -d '{\"keywords\": [\"Python\", \"Java\"], \"timeframe\": \"now 7-d\"}'\r\n  ```\r\n\r\n## Visualization\r\n\r\nThe flow of the Google Trends Comparison Script is visualized below using Mermaid:\r\n\r\n```mermaid\r\ngraph TD\r\n    A[User Input: Keywords \u0026 Timeframe] --\u003e B[Script Initialization]\r\n    B --\u003e C[Fetch Data from Google Trends API using pytrends]\r\n    C --\u003e D[Handle Rate-Limiting]\r\n    D --\u003e E[Process and Clean Data using Pandas]\r\n    E --\u003e F[Generate Comparison Plot with Matplotlib]\r\n    F --\u003e G[Save as PNG]\r\n    G --\u003e H[Output: google_trends_comparison.png]\r\n```\r\n\r\nThe flow of the API-based process is visualized below:\r\n\r\n```mermaid\r\ngraph TD\r\n    A[User Input: Keywords \u0026 Timeframe] --\u003e B[API Request to /compare]\r\n    B --\u003e C[Fetch Data from Google Trends API using pytrends]\r\n    C --\u003e D[Handle Rate-Limiting]\r\n    D --\u003e E[Process and Clean Data using Pandas]\r\n    E --\u003e F[Generate Comparison Plot with Matplotlib]\r\n    F --\u003e G[Save as PNG]\r\n    G --\u003e H[Return plot filename in API response]\r\n```\r\n\r\n## Error Handling\r\n\r\n- The script will handle cases where **no data is available** for the specified keywords.\r\n- In cases where Google returns a `400` error, the timeframe or keyword formatting may be incorrect.\r\n\r\n## License\r\n\r\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fronknight%2Fgoogle-trends-api-webserver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fronknight%2Fgoogle-trends-api-webserver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fronknight%2Fgoogle-trends-api-webserver/lists"}