Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4116d5f742 | |||
| 2ecab209c5 |
+7
-2
@@ -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"]
|
||||
@@ -264,7 +264,12 @@ REDDIT_USER_AGENT = os.getenv("REDDIT_USER_AGENT")
|
||||
REDDIT_SUBREDDITS = [
|
||||
"food",
|
||||
"FoodPorn",
|
||||
"spicy"
|
||||
"spicy",
|
||||
"KoreanFood",
|
||||
"JapaneseFood",
|
||||
"DessertPorn",
|
||||
"ChineseFood",
|
||||
"IndianFood"
|
||||
]
|
||||
FAST_FOOD_KEYWORDS = [
|
||||
"mcdonald", "burger king", "wendy", "taco bell", "kfc",
|
||||
|
||||
+4
-13
@@ -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()]
|
||||
if not eligible_sentences:
|
||||
eligible_sentences = [(i, s) for i, s in enumerate(sentences) if s.strip()]
|
||||
if not eligible_sentences:
|
||||
logging.error("No eligible sentences found for link insertion.")
|
||||
return summary
|
||||
|
||||
sentence_idx, sentence = random.choice(eligible_sentences)
|
||||
link_pattern = f'<a href="{source_url}">{source_name}</a>'
|
||||
|
||||
words = sentence.split()
|
||||
if len(words) < 5: # Ensure enough words for natural insertion
|
||||
# Insert the link at the end of the sentence
|
||||
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 += '.'
|
||||
|
||||
sentences[sentence_idx] = new_sentence
|
||||
new_para = ' '.join(sentences)
|
||||
|
||||
Reference in New Issue
Block a user