diff --git a/foodie_utils.py b/foodie_utils.py index 3df3367..e9c4e0d 100644 --- a/foodie_utils.py +++ b/foodie_utils.py @@ -615,11 +615,17 @@ def insert_link_naturally(summary, source_name, source_url): link_pattern = f'{source_name}' words = sentence.split() - if len(words) < 3: - new_sentence = f"{sentence} according to {link_pattern}." + if len(words) < 5: # Ensure enough words for natural insertion + new_sentence = f"{sentence.rstrip('.')} according to {link_pattern}." else: - split_point = random.randint(1, len(words)-2) - new_sentence = f"{' '.join(words[:split_point])}, according to {link_pattern}, {' '.join(words[split_point:])}" + 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 += '.' sentences[sentence_idx] = new_sentence new_para = ' '.join(sentences) @@ -749,13 +755,7 @@ def post_to_wp(post_data, category, link, author, image_url, original_source, im content = "Content unavailable. Check the original source for details." formatted_content = "\n".join(f"
{para}
" for para in content.split('\n') if para.strip()) - if image_url and image_source: - attribution = f"Image Source: {image_source}" - if page_url and uploader: - attribution = f'Image Source: {image_source} by {uploader}' - elif page_url: - attribution = f'Image Source: {image_source}' - formatted_content += f"\n{attribution}
" + # Removed the block that appends image attribution to the content author_id_map = { "owenjohnson": 10,