update geos google script

my-fix-branch
Shane 7 months ago
parent d7fd57af81
commit 31c8defc4a
  1. 17
      foodie_automator_google.py

@ -178,18 +178,23 @@ def fetch_duckduckgo_news_context(trend_title, hours=24):
logging.warning(f"DuckDuckGo News context fetch failed for '{trend_title}': {e}") logging.warning(f"DuckDuckGo News context fetch failed for '{trend_title}': {e}")
return trend_title return trend_title
def curate_from_google_trends(): def curate_from_google_trends(geo_list=['US']):
# Fetch Google Trends data # Fetch Google Trends data for each geo
trends = fetch_google_trends() all_trends = []
if not trends: for geo in geo_list:
trends = scrape_google_trends(geo=geo)
if trends:
all_trends.extend(trends)
if not all_trends:
print("No Google Trends data available") print("No Google Trends data available")
logging.info("No Google Trends data available") logging.info("No Google Trends data available")
return None, None, None return None, None, None
attempts = 0 attempts = 0
max_attempts = 10 max_attempts = 10
while attempts < max_attempts and trends: while attempts < max_attempts and all_trends:
trend = trends.pop(0) trend = all_trends.pop(0)
title = trend["title"] title = trend["title"]
link = trend.get("link", "https://trends.google.com/") link = trend.get("link", "https://trends.google.com/")
summary = trend.get("summary", "") summary = trend.get("summary", "")

Loading…
Cancel
Save