From 7c69b4a45110800c1e013a11b69bf1c430ad445e Mon Sep 17 00:00:00 2001 From: Shane Date: Sat, 10 May 2025 20:57:37 +1000 Subject: [PATCH] updage google regions --- foodie_automator_google.py | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/foodie_automator_google.py b/foodie_automator_google.py index e7b8f66..4ad6a35 100644 --- a/foodie_automator_google.py +++ b/foodie_automator_google.py @@ -250,15 +250,40 @@ def curate_from_google_trends(posted_titles_data, posted_titles, used_images_dat try: logging.debug(f"Using {len(posted_titles)} posted titles and {len(used_images)} used images") - trends = scrape_google_trends() - if not trends: - logging.info("No Google Trends data available") + # Define regions to scrape + regions = ['US', 'GB', 'AU'] + all_trends = [] + + # Scrape trends for each region + for geo in regions: + logging.info(f"Scraping Google Trends for geo={geo}") + trends = scrape_google_trends(geo=geo) + if trends: + logging.info(f"Collected {len(trends)} trends for geo={geo}") + all_trends.extend(trends) + else: + logging.warning(f"No trends collected for geo={geo}") + + # Remove duplicates by title and sort by search volume + unique_trends = [] + seen_titles = set() + for trend in all_trends: + if trend["title"] not in seen_titles: + unique_trends.append(trend) + seen_titles.add(trend["title"]) + + if not unique_trends: + logging.info("No Google Trends data available across regions") return None, None, False + # Sort trends by search volume in descending order + unique_trends.sort(key=lambda x: x["search_volume"], reverse=True) + logging.info(f"Total unique trends collected: {len(unique_trends)}") + attempts = 0 max_attempts = 10 - while attempts < max_attempts and trends: - trend = trends.pop(0) + while attempts < max_attempts and unique_trends: + trend = unique_trends.pop(0) title = trend["title"] link = trend.get("link", "") summary = trend.get("summary", "")