Every morning, merges headlines on your topic from two news services, drops the duplicates and sends one digest to Telegram.
Uses
GNews
Google TranslateNews API
Telegram
Morning news digest in Telegram
Every morning at 07:00, the last twenty-four hours of news on your topic is read from two independent services, GNews and News API, and merged into one Telegram message. Two services are used because they index different publishers, so between them they cover far more than either does alone.
You get one digest with each story once: headlines are matched on their text, ignoring case and spacing, and the second copy of a story is dropped. Each line carries the headline, the publisher and the link exactly as the service supplied them, with nothing summarised, rewritten or invented. If one service is down you still get the other's headlines, with a line saying which was missing, and the digest is sent on quiet mornings too, saying so. Headlines can be translated into a language you choose, and one that cannot be translated is sent in its original language rather than dropped.
You need a Telegram chat to send to and a topic to follow, plus connections to both news services.
newsTopic to blank.Set newsTopic to blank.digestChatId to blank.Set digestChatId to blank.translateInto to blank.Set translateInto to blank.headlineLanguage to en.Set headlineLanguage to en.headlinesPerSource to 8.Set headlinesPerSource to 8.maxHeadlines to 10.Set maxHeadlines to 10.sourceNotes.Start an empty list and save it as sourceNotes.gnewsArticles.Start an empty list and save it as gnewsArticles.sourceErrorIf a step below fails, save the error as sourceErrornewsTopic coverage. Save it as response.Search for recent newsTopic coverage. Save it as response.response.articles into one list and save it as gnewsArticles.Combine a list of [] and response.articles into one list and save it as gnewsArticles.GNews could not be read this morning. to the end of sourceNotes and save it as sourceNotes.Add GNews could not be read this morning. to the end of sourceNotes and save it as sourceNotes.sourceError as text.Show in the output: GNews search failed: sourceError as text.newsApiArticles.Start an empty list and save it as newsApiArticles.sourceErrorIf a step below fails, save the error as sourceErrornewsTopic coverage. Save it as response.Search for recent newsTopic coverage. Save it as response.response.articles into one list and save it as newsApiArticles.Combine a list of [] and response.articles into one list and save it as newsApiArticles.News API could not be read this morning. to the end of sourceNotes and save it as sourceNotes.Add News API could not be read this morning. to the end of sourceNotes and save it as sourceNotes.sourceError as text.Show in the output: News API search failed: sourceError as text.gnewsArticles and newsApiArticles into one list and save it as allArticles.Combine gnewsArticles and newsApiArticles into one list and save it as allArticles.seenHeadlines.Start an empty list and save it as seenHeadlines.digestLines.Start an empty list and save it as digestLines.article in allArticles:For each article in allArticles:digestLines is greater than or equal to maxHeadlines multiplied…If the length of digestLines is greater than or equal to maxHeadlines multiplied…articleErrorIf a step below fails, save the error as articleErrorarticle.title and save it as headline.Trim article.title and save it as headline.headline lowercase and save it as headlineKey.Make headline lowercase and save it as headlineKey.headline isn't empty and seenHeadlines doesn't contain headlineKeyIf headline isn't empty and seenHeadlines doesn't contain headlineKeyheadlineKey to the end of seenHeadlines and save it as seenHeadlines.Add headlineKey to the end of seenHeadlines and save it as seenHeadlines.shownHeadline to headline.Set shownHeadline to headline.translateInto isn't emptyIf translateInto isn't emptytranslateErrorIf a step below fails, save the error as translateErrorheadline into translateInto. Save it as translation.Translate headline into translateInto. Save it as translation.translation.translated_text and save it as translatedText.Trim translation.translated_text and save it as translatedText.translatedText isn't emptyIf translatedText isn't emptyshownHeadline to translatedText.Change shownHeadline to translatedText.' with ' in shownHeadline and save it as shownHeadline.Replace ' with ' in shownHeadline and save it as shownHeadline." with " in shownHeadline and save it as shownHeadline.Replace " with " in shownHeadline and save it as shownHeadline.& with & in shownHeadline and save it as shownHeadline.Replace & with & in shownHeadline and save it as shownHeadline.translateError as text.Show in the output: Could not translate a headline, keeping the original: translateError as text.publisherPart to blank.Set publisherPart to blank.missingFieldIf a step below fails, save the error as missingFieldarticle.source_name and save it as fieldValue.Trim article.source_name and save it as fieldValue.fieldValue isn't emptyIf fieldValue isn't emptypublisherPart to - fieldValue.Change publisherPart to - fieldValue.linkPart to blank.Set linkPart to blank.missingFieldIf a step below fails, save the error as missingFieldarticle.url and save it as fieldValue.Trim article.url and save it as fieldValue.fieldValue isn't emptyIf fieldValue isn't emptylinkPart to Change linkPart to
fieldValue.shownHeadline plus publisherPart plus linkPart to the end of digestLines and save it as digestLines.Add shownHeadline plus publisherPart plus linkPart to the end of digestLines and save it as digestLines.articleError as text.Show in the output: Skipped an article with no headline: articleError as text.heading to Morning news - newsTopic.Set heading to Morning news - newsTopic.digestLines with a blank line and save it as digestBody.Join digestLines with a blank line and save it as digestBody.digestLines is emptyIf digestLines is emptydigestBody to Nothing new in the last 24 hours on this topic..Change digestBody to Nothing new in the last 24 hours on this topic..sourceNotes with a space and save it as sourceNotice.Join sourceNotes with a space and save it as sourceNotice.message to headingSet message to heading
digestBody.sourceNotice isn't emptyIf sourceNotice isn't emptymessage to messageChange message to message
sourceNotice.message to 3900 characters and save it as message.Shorten message to 3900 characters and save it as message.digestChatId.Send a message to chat digestChatId.message