Skip to content

Commit

Permalink
fix #69, #70
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Myles McDonnell committed Mar 5, 2023
1 parent bffe48e commit 27de2d1
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
8 changes: 3 additions & 5 deletions R/atom_parse.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ atom_parse <- function(response, list, clean_tags, parse_dates) {
# get default namespace
ns_entry <- xml_ns(res) %>% attributes() %>% .[[1]] %>% .[[1]]

# metadata: id, title, updated necessary,
# metadata: id, title, updated necessary
metadata <- tibble(
feed_title = xml_find_first(res, glue("{ns_entry}:title")) %>% xml_text(),
feed_url = xml_find_first(res, glue("{ns_entry}:id")) %>% xml_text(),
Expand Down Expand Up @@ -38,10 +38,7 @@ atom_parse <- function(response, list, clean_tags, parse_dates) {
meta <- bind_cols(metadata, meta_optional)
# entries
# necessary: id, title, updated

res_entry <- xml_find_all(res, glue("{ns_entry}:entry"))
e_link <- xml_find_first(res_entry, glue("{ns_entry}:link")) %>%
xml_attr("href")

# optional
entries <- tibble(
Expand All @@ -51,7 +48,8 @@ atom_parse <- function(response, list, clean_tags, parse_dates) {
entry_author = safe_run(res_entry, "all", glue("{ns_entry}:author")),
entry_enclosure = safe_run(res_entry, "all", glue("{ns_entry}:enclosure")),
entry_content = safe_run(res_entry, "all", glue("{ns_entry}:content")),
entry_link = ifelse(!is.null(e_link), e_link, def),
# https://github.com/RobertMyles/tidyRSS/issues/70
entry_link = xml_attr(xml_find_first(res_entry, glue("{ns_entry}:link")),"href"),
entry_summary = safe_run(res_entry, "all", glue("{ns_entry}:summary")),
entry_category = list(NA),
entry_published = safe_run(res_entry, "all", glue("{ns_entry}:published")),
Expand Down
3 changes: 1 addition & 2 deletions R/json_parse.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ json_parse <- function(response, list, clean_tags, parse_dates) {
language = return_exists(res$language),
expired = return_exists(res$expired),
icon = return_exists(res$icon),
favicon = return_exists(res$favicon),
expired = return_exists(res$expired)
favicon = return_exists(res$favicon)
)

entries <- tibble(
Expand Down
6 changes: 2 additions & 4 deletions R/rss_parse.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ rss_parse <- function(response, list, clean_tags, parse_dates) {
)
# optional metadata: language, copyright, managingEditor, webMaster, pubDate,
# lastBuildDate; category, generator, docs, cloud, link, managingEditor,
# podcast:guid, podcast:license, podcast:locked, podcast:funding,
# podcast:guid, podcast:license, podcast:locked, podcast:funding,
# podcast:location, podcast:trailer, ttl, image, textInput,
# skipHours, skipDays
meta_optional <- tibble(
Expand All @@ -29,7 +29,6 @@ rss_parse <- function(response, list, clean_tags, parse_dates) {
)),
feed_generator = safe_run(channel, "first", "//*[name()='generator']"),
feed_docs = safe_run(channel, "first", "//*[name()='docs']"),
feed_link = safe_run(channel, "first", "//*[name()='link']"),
feed_managingEditor = safe_run(channel, "first", "//*[name()='managingEditor']"),
feed_webMaster = safe_run(channel, "first", "//*[name()='webMaster']"),
feed_guid = safe_run(channel, "first", "//*[name()='podcast:guid']"),
Expand All @@ -50,11 +49,10 @@ rss_parse <- function(response, list, clean_tags, parse_dates) {
item_title = map(res_entry, "title", .default = def) %>% unlist(),
item_link = map(res_entry, "link", .default = def) %>% unlist(),
item_description = map(res_entry, "description", .default = def) %>%
unlist() %>% discard(safe_check_comment),
replace_null() %>% discard(safe_check_comment) %>% unlist(),
item_pub_date = map(res_entry, "pubDate", .default = def) %>% unlist(),
item_guid = map(res_entry, "guid", .default = def) %>% unlist(),
item_author = map(res_entry, "author", .default = def),
item_enclosure = map(res_entry, "enclosure", .default = def),
item_season = map(res_entry, "podcast:season", .default = def),
item_episode = map(res_entry, "podcast:episode", .default = def),
item_enclosure = map(res_entry, "enclosure", .default = def),
Expand Down
7 changes: 7 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,10 @@ safe_check_comment <- function(x) {
}
x == "[ comment ]"
}

# From https://github.com/RobertMyles/tidyRSS/issues/69

replace_null <- function(x){
x <- map(x, ~ replace(.x, is.null(.x), NA_character_))
map(x, ~ if(is.list(.x)) replace_null(.x) else .x)
}

0 comments on commit 27de2d1

Please sign in to comment.