{"id":18655503,"url":"https://github.com/ronknight/google-trends","last_synced_at":"2026-03-07T08:02:34.154Z","repository":{"id":257953535,"uuid":"873177650","full_name":"ronknight/google-trends","owner":"ronknight","description":"🔧 A Python-based script to compare the popularity of multiple keywords using Google Trends data.","archived":false,"fork":false,"pushed_at":"2025-06-02T22:57:42.000Z","size":696,"stargazers_count":0,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-17T18:51:07.759Z","etag":null,"topics":["google-trends-api","pytrends"],"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,"zenodo":null},"funding":{"patreon":"PinoyITSolution"}},"created_at":"2024-10-15T18:17:27.000Z","updated_at":"2025-06-02T22:55:21.000Z","dependencies_parsed_at":"2024-12-27T14:32:24.229Z","dependency_job_id":"72eea634-f464-44e6-b008-efd4eb826cf6","html_url":"https://github.com/ronknight/google-trends","commit_stats":null,"previous_names":["ronknight/google-trends"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/ronknight/google-trends","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ronknight%2Fgoogle-trends","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ronknight%2Fgoogle-trends/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ronknight%2Fgoogle-trends/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ronknight%2Fgoogle-trends/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ronknight","download_url":"https://codeload.github.com/ronknight/google-trends/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ronknight%2Fgoogle-trends/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30209796,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-07T05:23:27.321Z","status":"ssl_error","status_checked_at":"2026-03-07T05:00:17.256Z","response_time":53,"last_error":"SSL_read: 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":["google-trends-api","pytrends"],"created_at":"2024-11-07T07:19:08.772Z","updated_at":"2026-03-07T08:02:34.145Z","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-2\"\u003eGoogle Trends Comparison Tool\u003c/a\u003e\u003c/h1\u003e\n\n\u003ch4 align=\"center\"\u003e🔧 A Python-based web application to compare the popularity of multiple keywords using Google Trends data with an easy-to-use web interface.\u003c/h4\u003e\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://twitter.com/PinoyITSolution\"\u003e\u003cimg src=\"https://img.shields.io/twitter/follow/PinoyITSolution?style=social\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/ronknight?tab=followers\"\u003e\u003cimg src=\"https://img.shields.io/github/followers/ronknight?style=social\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/ronknight/ronknight/stargazers\"\u003e\u003cimg src=\"https://img.shields.io/github/stars/BEPb/BEPb.svg?logo=github\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/ronknight/ronknight/network/members\"\u003e\u003cimg src=\"https://img.shields.io/github/forks/BEPb/BEPb.svg?color=blue\u0026logo=github\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/ronknight/google-trends-2/issues\"\u003e\u003cimg src=\"https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/ronknight/google-trends-2/blob/master/LICENSE\"\u003e\u003cimg src=\"https://img.shields.io/badge/License-MIT-yellow.svg\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/ronknight\"\u003e\u003cimg src=\"https://img.shields.io/badge/Made%20with%20%F0%9F%A4%8D%20by%20-%20Ronknight%20-%20red\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"#overview\"\u003eOverview\u003c/a\u003e •\n  \u003ca href=\"#features\"\u003eFeatures\u003c/a\u003e •\n  \u003ca href=\"#prerequisites\"\u003ePrerequisites\u003c/a\u003e •\n  \u003ca href=\"#installation\"\u003eInstallation\u003c/a\u003e •\n  \u003ca href=\"#how-to-use\"\u003eHow to Use\u003c/a\u003e •\n  \u003ca href=\"#web-interface\"\u003eWeb Interface\u003c/a\u003e •\n  \u003ca href=\"#visualization\"\u003eVisualization\u003c/a\u003e •\n  \u003ca href=\"#error-handling\"\u003eError Handling\u003c/a\u003e •\n  \u003ca href=\"#project-structure\"\u003eProject Structure\u003c/a\u003e •\n  \u003ca href=\"#license\"\u003eLicense\u003c/a\u003e\n\u003c/p\u003e\n\n## Overview\n\nThis Python Flask application allows you to compare the popularity of two or three keywords over a specified timeframe using Google Trends data. The application fetches interest over time for the provided keywords and visualizes the trends using `matplotlib`. The tool provides a user-friendly web interface for submitting keywords and displaying the resulting comparison image directly in your browser.\n\n## Features\n\n- Compare the search interest of **2 to 5 keywords** over a custom time period\n- **Multiple timeframe options**, including past day, past 7 days, past 12 months, past 5 years, and 2004 to present\n- Clean, responsive **web interface** for easy data input and result display\n- **Visual plot output** saved as a `.png` image and displayed in the browser\n- **Smart error handling** with user-friendly error messages and suggestions\n- **Rate-limiting protection** with automatic retries and exponential backoff\n- **Custom user agent rotation** to prevent blocking from Google Trends\n- Enhanced reliability for fetching Google Trends data through updated dependencies.\n- Improved User-Agent randomization to minimize request blocking.\n- Refined retry logic with jitter for more robust connection handling.\n- Provides a JSON API endpoint (`/api/compare`) for programmatic access to the Google Trends data.\n\n## Prerequisites\n\nBefore running the application, ensure you have Python installed along with the following packages:\n\n- `Flask`\n- `Flask-CORS`\n- `pytrends`\n- `matplotlib`\n- `pandas`\n- `requests`\n\n## Installation\n\n1. Clone the repository:\n   ```bash\n   git clone https://github.com/ronknight/google-trends-2.git\n   cd google-trends-2\n   ```\n\n2. Install the required packages:\n   ```bash\n   pip install -r requirements.txt\n   ```\n\n## How to Use\n\n### Running the Web Application\n\n1. Start the Flask server:\n   ```bash\n   python app.py\n   ```\n\n2. Open your browser and navigate to `http://localhost:5000`\n\n3. Enter your keywords and select a timeframe from the dropdown menu\n\n4. Click \"Compare Trends\" to generate and view the comparison\n\n## Web Interface\n\nThe application provides a clean, user-friendly web interface with the following features:\n\n- **Intuitive Form**: Easy input for two required keywords and up to three additional optional keywords (total of 5).\n- **Timeframe Selection**: Dropdown menu with various time period options\n- **Loading Indicator**: Visual feedback during data retrieval with a progress bar\n- **Error Display**: Clear error messages with helpful suggestions when issues occur\n- **Responsive Design**: Works well on both desktop and mobile devices\n\n### Interface Screenshots\n\n#### Form Interface\n![Form Interface](static/form_interface.png)\n\n*The main form where users enter keywords and select a timeframe*\n\n#### Loading Screen\n![Loading Screen](static/form_loading.png)\n\n*Loading screen with progress bar shown while fetching data from Google Trends*\n\n#### Results Display\n![Results Screen](static/form_results.png)\n\n*The results page displaying the Google Trends comparison graph*\n\n### Available Timeframes:\n\n- Past 12 months (default)\n- Past 7 days\n- Past day\n- Past 5 years\n- 2004 to present\n\n\n\n## Visualization\n\nThe Google Trends data is visualized with the following features:\n\n- **Line graph** showing interest over time for each keyword\n- **Color coding** to distinguish between different keywords\n- **Appropriate date formatting** based on the selected timeframe\n- **Grid lines** for better readability\n- **Legend** to identify which line represents which keyword\n\n### Process Flow\n\nThe flow of the Google Trends Comparison Tool is visualized below using Mermaid:\n\n```mermaid\ngraph TD\n    A[User Input: Keywords \u0026 Timeframe] --\u003e B[Script Initialization]\n    B --\u003e C[Fetch Data from Google Trends API using pytrends]\n    C --\u003e D[Handle Rate-Limiting]\n    D --\u003e E[Process and Clean Data using Pandas]\n    E --\u003e F[Generate Comparison Plot with Matplotlib]\n    F --\u003e G[Save as PNG]\n    G --\u003e H[Output: google_trends_comparison.png]\n```\n\nThe flow of the web application process is visualized below:\n\n```mermaid\ngraph TD\n    A[User Input: Keywords \u0026 Timeframe] --\u003e B[Form Submission]\n    B --\u003e C[Fetch Data from Google Trends API using pytrends]\n    C --\u003e D[Handle Rate-Limiting with Retries]\n    D --\u003e E[Process and Clean Data using Pandas]\n    E --\u003e F[Generate Comparison Plot with Matplotlib]\n    F --\u003e G[Save as PNG]\n    G --\u003e H[Display Results in Browser]\n```\n\n## Error Handling\n\nThe application includes robust error handling:\n\n- **Rate limiting detection** with automatic retries using exponential backoff. Error messages now provide more specific feedback if all retries fail, including a suggestion to use a dedicated proxy service if problems persist.\n- **User-friendly error page** with clear explanation of what went wrong\n- **Helpful suggestions** for resolving common issues like:\n  - Using different keywords\n  - Waiting before trying again (for rate-limiting issues)\n  - Checking keyword spelling\n  - Using shorter timeframes\n\n## Advanced Configuration\n\n### Proxy Configuration\n\nIf you are experiencing persistent issues with requests being blocked by Google, or if you prefer to route `pytrends` traffic through a proxy, you can configure the application to use an HTTP/S proxy.\n\nTo do this, set the following environment variables before running the application:\n\n```bash\nexport HTTP_PROXY=\"http://your_proxy_address:port\"\nexport HTTPS_PROXY=\"https://your_proxy_address:port\"\n```\n\nReplace `your_proxy_address:port` with the actual address and port of your proxy server. If both variables are set, `pytrends` will use them for its requests. Ensure your proxy supports HTTPS if you intend to use `HTTPS_PROXY`.\n\n## JSON API Usage\n\nThe application provides a JSON API endpoint for programmatic access to Google Trends data.\n\n- **URL:** `/api/compare`\n- **Method:** `POST`\n- **Request Body:** JSON payload\n\n### Request Payload Parameters\n\n- `keywords`: (list of strings) A list of 2 to 5 keywords to compare. Required.\n- `timeframe`: (string) The timeframe for the trends data (e.g., \"today 12-m\", \"today 1-m\", \"all\"). Required.\n\n### Example Request Payload\n\n```json\n{\n    \"keywords\": [\"python\", \"javascript\", \"java\"],\n    \"timeframe\": \"today 12-m\"\n}\n```\n\n### Example cURL Command\n\nYou can test the API endpoint using the following `curl` command:\n\n```bash\ncurl -X POST -H \"Content-Type: application/json\" \\\n  -d '{\"keywords\": [\"disney\", \"hello kitty\", \"dove\", \"colgate\", \"batman\"], \"timeframe\": \"today 12-m\"}' \\\n  http://localhost:5000/api/compare -o good_response.json\n```\n\nThis command sends a POST request to the API with five keywords and saves the JSON response to `good_response.json`.\n\n### Success Response\n\n- **Code:** `200 OK`\n- **Content:** A JSON object representing the pandas DataFrame in 'table' orientation, which includes schema and data. Dates are formatted in ISO 8601 format (e.g., `YYYY-MM-DDTHH:mm:ss.sssZ`).\n\n#### Example Success Response Structure (Simplified)\n\n```json\n{\n  \"schema\": {\n    \"fields\": [\n      {\"name\": \"date\", \"type\": \"datetime\"},\n      {\"name\": \"keyword1\", \"type\": \"integer\"},\n      {\"name\": \"keyword2\", \"type\": \"integer\"},\n      // ... up to 5 keywords\n      // {\"name\": \"isPartial\", \"type\": \"boolean\"} // May be present\n    ],\n    \"primaryKey\": [\"date\"],\n    \"pandas_version\": \"1.x.x\" // Example pandas version\n  },\n  \"data\": [\n    {\"date\": \"YYYY-MM-DDTHH:mm:ss.sssZ\", \"keyword1\": 75, \"keyword2\": 80, /* ... */},\n    // ... more data points\n  ]\n}\n```\n*Note: The actual field names for keywords in the `data` array will match the keywords you provided in the request.*\n\n### Error Responses\n\n- **`400 Bad Request`**: Invalid JSON payload, missing required fields, or invalid keyword/timeframe format. The response body will contain a JSON object with an \"error\" key describing the issue.\n- **`404 Not Found`**: No data available for the given keywords or timeframe.\n- **`429 Too Many Requests`**: If the server encounters rate limiting from Google Trends after multiple retries.\n- **`500 Internal Server Error`**: For other server-side errors during data processing.\n\n## Project Structure\n\n```\ngoogle-trends-2/\n├── app.py                  # Main Flask application\n├── requirements.txt        # Python dependencies\n├── LICENSE                 # MIT License\n├── README.md               # Project documentation\n├── static/                 # Static assets\n│   ├── favicon.ico         # Website favicon\n│   └── google_trends_comparison.png  # Generated plot image\n└── templates/              # HTML templates\n    ├── error.html          # Error display page\n    ├── image.html          # Results display page\n    └── index.html          # Main form page\n```\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fronknight%2Fgoogle-trends","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fronknight%2Fgoogle-trends","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fronknight%2Fgoogle-trends/lists"}