From 64d17d5599fc358a870d961c228426d2adab59cf Mon Sep 17 00:00:00 2001 From: Shane Date: Sun, 4 May 2025 10:27:26 +1000 Subject: [PATCH] try --- foodie_automator_rss.py | 7 ++++- foodie_utils.py | 70 +++++++++++++++++++++++++++++------------ 2 files changed, 56 insertions(+), 21 deletions(-) diff --git a/foodie_automator_rss.py b/foodie_automator_rss.py index 05c5743..7d774ef 100644 --- a/foodie_automator_rss.py +++ b/foodie_automator_rss.py @@ -236,13 +236,18 @@ def curate_from_rss(): print(f"Trying RSS Article: {title} from {source_name}") logging.info(f"Trying RSS Article: {title} from {source_name}") - image_query, relevance_keywords, skip = smart_image_and_filter(title, summary) + image_query, relevance_keywords, main_topic, skip = smart_image_and_filter(title, summary) if skip: print(f"Skipping filtered RSS article: {title}") logging.info(f"Skipping filtered RSS article: {title}") attempts += 1 continue + # Pass main_topic to get_flickr_image for use in fallbacks + image_url, image_source, uploader, page_url = get_flickr_image(image_query, relevance_keywords, main_topic) + if not image_url: + image_url, image_source, uploader, page_url = get_image(image_query) + # Fetch additional context via DDG ddg_context = fetch_duckduckgo_news_context(title) scoring_content = f"{title}\n\n{summary}\n\nContent: {content}\n\nAdditional Context: {ddg_context}" diff --git a/foodie_utils.py b/foodie_utils.py index 6143211..cc25fde 100644 --- a/foodie_utils.py +++ b/foodie_utils.py @@ -341,9 +341,10 @@ def smart_image_and_filter(title, summary): prompt = ( "Analyze this article title and summary. Extract key entities (brands, locations, cuisines, or topics) " "for an image search about food industry trends or viral content. Prioritize specific terms if present, " - "otherwise focus on the main theme. " + "otherwise focus on the main theme. Also identify the main topic of the article (e.g., a specific food item or cuisine). " "Return 'SKIP' if the article is about home appliances, recipes, promotions, or contains 'homemade', else 'KEEP'. " - "Return as JSON with double quotes for all property names and string values (e.g., {\"image_query\": \"specific term\", \"relevance\": [\"keyword1\", \"keyword2\"], \"action\": \"KEEP\" or \"SKIP\"})." + "Return as JSON with double quotes for all property names and string values (e.g., " + "{\"image_query\": \"specific term\", \"relevance\": [\"keyword1\", \"keyword2\"], \"main_topic\": \"main food item\", \"action\": \"KEEP\" or \"SKIP\"})." ) response = client.chat.completions.create( @@ -357,39 +358,52 @@ def smart_image_and_filter(title, summary): raw_result = response.choices[0].message.content.strip() logging.info(f"Raw GPT smart image/filter response: '{raw_result}'") - # Remove ```json markers and fix single quotes in JSON structure cleaned_result = re.sub(r'```json\s*|\s*```', '', raw_result).strip() - # Replace single quotes with double quotes, but preserve single quotes within string values fixed_result = re.sub(r"(?