diff --git a/foodie_config.py b/foodie_config.py index 289c045..7cbb7c9 100644 --- a/foodie_config.py +++ b/foodie_config.py @@ -245,7 +245,7 @@ RSS_FEED_NAMES = { "https://www.eater.com/rss/full.xml": ("Eater", "https://www.eater.com/"), "https://www.nrn.com/rss.xml": ("Nation's Restaurant News", "https://www.nrn.com/"), "https://rss.nytimes.com/services/xml/rss/nyt/DiningandWine.xml": ("The New York Times", "https://www.nytimes.com/section/food"), - "https://www.theguardian.com/food/rss": ("The Guardian Food", "https://www.theguardian.com/food") + "https://www.theguardian.com/food/rss": ("The Guardian", "https://www.theguardian.com/food") } RECIPE_KEYWORDS = ["recipe", "cook", "bake", "baking", "cooking", "ingredient", "method", "mix", "stir", "preheat", "dinners", "make", "dish", "healthy"] diff --git a/foodie_utils.py b/foodie_utils.py index e9c4e0d..0206683 100644 --- a/foodie_utils.py +++ b/foodie_utils.py @@ -607,25 +607,16 @@ def insert_link_naturally(summary, source_name, source_url): target_para = random.choice(eligible_paragraphs) sentences = re.split(r'(?<=[.!?])\s+', target_para.strip()) - eligible_sentences = [(i, s) for i, s in enumerate(sentences) if i < len(sentences)-1 and s.strip()] + eligible_sentences = [(i, s) for i, s in enumerate(sentences) if s.strip()] if not eligible_sentences: - eligible_sentences = [(i, s) for i, s in enumerate(sentences) if s.strip()] + logging.error("No eligible sentences found for link insertion.") + return summary sentence_idx, sentence = random.choice(eligible_sentences) link_pattern = f'{source_name}' - words = sentence.split() - if len(words) < 5: # Ensure enough words for natural insertion - new_sentence = f"{sentence.rstrip('.')} according to {link_pattern}." - else: - split_point = random.randint(2, len(words)-3) # Split further into the sentence - # Remove trailing punctuation from the first part and ensure proper grammar - first_part = ' '.join(words[:split_point]).rstrip(',') - second_part = ' '.join(words[split_point:]).lstrip(',') - new_sentence = f"{first_part} according to {link_pattern} {second_part}" - # Ensure the sentence ends with a period - if not new_sentence.endswith('.'): - new_sentence += '.' + # Insert the link at the end of the sentence + new_sentence = f"{sentence.rstrip('.')} according to {link_pattern}." sentences[sentence_idx] = new_sentence new_para = ' '.join(sentences)