fix
This commit is contained in:
@@ -208,7 +208,7 @@ def curate_from_google_trends(geo_list=['US']):
|
|||||||
print(f"Trying Google Trend: {title} from {source_name}")
|
print(f"Trying Google Trend: {title} from {source_name}")
|
||||||
logging.info(f"Trying Google Trend: {title} from {source_name}")
|
logging.info(f"Trying Google Trend: {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:
|
if skip:
|
||||||
print(f"Skipping filtered Google Trend: {title}")
|
print(f"Skipping filtered Google Trend: {title}")
|
||||||
logging.info(f"Skipping filtered Google Trend: {title}")
|
logging.info(f"Skipping filtered Google Trend: {title}")
|
||||||
@@ -250,7 +250,7 @@ def curate_from_google_trends(geo_list=['US']):
|
|||||||
|
|
||||||
final_summary = insert_link_naturally(final_summary, source_name, link)
|
final_summary = insert_link_naturally(final_summary, source_name, link)
|
||||||
|
|
||||||
post_data, author, category, image_url, image_source, uploader, pixabay_url = prepare_post_data(final_summary, title)
|
post_data, author, category, image_url, image_source, uploader, pixabay_url = prepare_post_data(final_summary, title, main_topic)
|
||||||
if not post_data:
|
if not post_data:
|
||||||
attempts += 1
|
attempts += 1
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -266,7 +266,7 @@ def curate_from_reddit():
|
|||||||
print(f"Trying Reddit Post: {title} from {source_name}")
|
print(f"Trying Reddit Post: {title} from {source_name}")
|
||||||
logging.info(f"Trying Reddit Post: {title} from {source_name}")
|
logging.info(f"Trying Reddit Post: {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 or any(keyword in title.lower() or keyword in raw_title.lower() for keyword in RECIPE_KEYWORDS + ["homemade"]):
|
if skip or any(keyword in title.lower() or keyword in raw_title.lower() for keyword in RECIPE_KEYWORDS + ["homemade"]):
|
||||||
print(f"Skipping filtered Reddit post: {title}")
|
print(f"Skipping filtered Reddit post: {title}")
|
||||||
logging.info(f"Skipping filtered Reddit post: {title}")
|
logging.info(f"Skipping filtered Reddit post: {title}")
|
||||||
|
|||||||
@@ -282,8 +282,9 @@ def curate_from_rss():
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
final_summary = insert_link_naturally(final_summary, source_name, link)
|
final_summary = insert_link_naturally(final_summary, source_name, link)
|
||||||
post_data, author, category, image_url, image_source, uploader, pixabay_url = prepare_post_data(final_summary, title)
|
post_data, author, category, image_url, image_source, uploader, pixabay_url = prepare_post_data(final_summary, title, main_topic)
|
||||||
if not post_data:
|
if not post_data:
|
||||||
|
logging.info(f"Post data preparation failed for '{title}'")
|
||||||
attempts += 1
|
attempts += 1
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|||||||
+55
-34
@@ -1158,42 +1158,63 @@ def select_best_author(summary):
|
|||||||
logging.error(f"Author selection failed: {e}")
|
logging.error(f"Author selection failed: {e}")
|
||||||
return "owenjohnson"
|
return "owenjohnson"
|
||||||
|
|
||||||
def prepare_post_data(final_summary, original_title, context_info=""):
|
def prepare_post_data(summary, title, main_topic=None):
|
||||||
innovative_title = generate_title_from_summary(final_summary)
|
try:
|
||||||
if not innovative_title:
|
logging.info(f"Preparing post data for summary: {summary[:100]}...")
|
||||||
logging.info(f"Title generation failed for '{original_title}' {context_info}")
|
|
||||||
return None, None, None, None, None, None, None
|
prompt = (
|
||||||
|
"Generate a concise, engaging title (5-15 words) for this food-related article summary. "
|
||||||
# Pass innovative_title and final_summary as separate arguments
|
"The title should be catchy, avoid emojis, and not reproduce the original title verbatim. "
|
||||||
search_query, relevance_keywords, _ = generate_image_query(innovative_title, final_summary)
|
"Return the title as plain text."
|
||||||
if not search_query:
|
)
|
||||||
logging.info(f"Image query generation failed for '{innovative_title}' {context_info}")
|
|
||||||
return None, None, None, None, None, None, None
|
response = client.chat.completions.create(
|
||||||
|
model=LIGHT_TASK_MODEL,
|
||||||
logging.info(f"Fetching Flickr image for query: '{search_query}' {context_info}")
|
messages=[
|
||||||
image_url, image_source, uploader, page_url = get_flickr_image(search_query, relevance_keywords)
|
{"role": "system", "content": prompt},
|
||||||
|
{"role": "user", "content": summary}
|
||||||
if not image_url:
|
],
|
||||||
logging.info(f"Flickr fetch failed for '{search_query}' - falling back to Pixabay {context_info}")
|
max_tokens=50,
|
||||||
# Use the same title and summary for fallback
|
temperature=0.7
|
||||||
image_query, _, _ = generate_image_query(innovative_title, final_summary)
|
)
|
||||||
image_url, image_source, uploader, page_url = get_image(image_query)
|
new_title = response.choices[0].message.content.strip()
|
||||||
|
logging.info(f"Generated new title: '{new_title}'")
|
||||||
|
|
||||||
|
search_query, relevance_keywords, skip_flag = smart_image_and_filter(new_title, summary)
|
||||||
|
if skip_flag:
|
||||||
|
logging.info("Summary filtered out during post preparation")
|
||||||
|
return None, None, None, None, None, None, None
|
||||||
|
|
||||||
|
image_url, image_source, uploader, page_url = get_flickr_image(search_query, relevance_keywords, main_topic)
|
||||||
if not image_url:
|
if not image_url:
|
||||||
logging.info(f"Pixabay fetch failed for title '{innovative_title}' - falling back to summary {context_info}")
|
image_url, image_source, uploader, page_url = get_image(search_query)
|
||||||
image_query, _, _ = generate_image_query(final_summary, final_summary) # Using summary as both title and summary for fallback
|
|
||||||
image_url, image_source, uploader, page_url = get_image(image_query)
|
if not image_url:
|
||||||
if not image_url:
|
logging.warning("No image found for post, skipping")
|
||||||
logging.info(f"Image fetch failed again for '{original_title}' - proceeding without image {context_info}")
|
return None, None, None, None, None, None, None
|
||||||
|
|
||||||
|
pixabay_url = page_url if image_source == "Pixabay" else None
|
||||||
|
|
||||||
|
authors = ["Aisha Patel", "Ravi Sharma", "Mei Lin", "Carlos Rivera"]
|
||||||
|
author = random.choice(authors)
|
||||||
|
|
||||||
|
categories = ["Food", "Trends", "Eats", "Culture"]
|
||||||
|
category = random.choice(categories)
|
||||||
|
|
||||||
|
post_data = {
|
||||||
|
"title": new_title,
|
||||||
|
"content": summary,
|
||||||
|
"status": "publish",
|
||||||
|
"author": author,
|
||||||
|
"categories": [category]
|
||||||
|
}
|
||||||
|
|
||||||
|
logging.info(f"Post data prepared: Title: '{new_title}', Category: {category}, Author: {author}")
|
||||||
|
return post_data, author, category, image_url, image_source, uploader, pixabay_url
|
||||||
|
|
||||||
post_data = {"title": innovative_title, "content": final_summary}
|
except Exception as e:
|
||||||
selected_username = select_best_author(final_summary)
|
logging.error(f"Failed to prepare post data: {e}")
|
||||||
author = next((a for a in AUTHORS if a["username"] == selected_username), None)
|
return None, None, None, None, None, None, None
|
||||||
if not author:
|
|
||||||
logging.error(f"Author '{selected_username}' not found in AUTHORS, defaulting to owenjohnson")
|
|
||||||
author = {"username": "owenjohnson", "password": "rfjk xhn6 2RPy FuQ9 cGlU K8mC"}
|
|
||||||
category = generate_category_from_summary(final_summary)
|
|
||||||
|
|
||||||
return post_data, author, category, image_url, image_source, uploader, page_url
|
|
||||||
|
|
||||||
def save_post_to_recent(post_title, post_url, author_username, timestamp):
|
def save_post_to_recent(post_title, post_url, author_username, timestamp):
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user