Skip to content

Commit

Permalink
refactor: make create_newsletter_content() more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
maelle committed Dec 19, 2024
1 parent cc3866e commit c267d7c
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions R/create_newsletter_content.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@
#'
create_newsletter_content <- function() {
feed <- xml2::read_xml("https://ropensci.org/rbloggers/index.xml")
post <- xml2::xml_find_first(feed, "//item/description") %>%
posts <- xml2::xml_find_all(feed, "//item")
post_xml <- posts[grepl("rOpenSci News Digest",
purrr::map_chr(posts, \(x) xml2::xml_text(xml2::xml_find_first(x, "title")))
)][[1]]

post <- post_xml %>%
xml2::xml_find_first("description") %>%
as.character() %>%
textutils::HTMLdecode() %>%
xml2::read_html()

# find post URL
url <- xml2::xml_find_first(feed, "//guid") %>%
url <- xml2::xml_find_first(post_xml, ".//guid") %>%
xml2::xml_text()

# URLS
Expand Down

0 comments on commit c267d7c

Please sign in to comment.