Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

news_ 로 접두사 결정. #153

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion R/getCategory.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
#' @param fresh get data from online. Default is FALSE using cached built-in data.
#' @export
getCategory <- function(fresh = FALSE) {
news_category(fresh)
}

news_category <- function(fresh = FALSE) {
if (!fresh) {
return(news_category)
return(news_category_data)
}
mcate <- getMainCategory()
cate <- list()
Expand Down
6 changes: 3 additions & 3 deletions R/getComment.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
getComment <- function(turl,
count = 10,
type = c("df", "list")) {
get_comment(turl, count, type)
news_comment(turl, count, type)
}

#' Get All Comment
Expand All @@ -37,13 +37,13 @@ getComment <- function(turl,
#' getAllComment("https://n.news.naver.com/mnews/article/214/0001195110")
#' }
getAllComment <- function(turl) {
get_comment(turl, "all", "df")
news_comment(turl, "all", "df")
}

#' @importFrom purrr when
#' @importFrom httr2 req_perform resp_body_string
#' @importFrom jsonlite fromJSON
get_comment <- function(turl,
news_comment <- function(turl,
count = 10,
type = c("df", "list")) {
. <- NULL
Expand Down
6 changes: 3 additions & 3 deletions R/getCommentHistory.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ getCommentHistory <- function(turl,
commentNo,
count = 10,
type = c("df", "list")) {
get_comment_history(turl, commentNo, count, type)
news_comment_history(turl, commentNo, count, type)
}

#' Get All Comment History
Expand All @@ -39,12 +39,12 @@ getCommentHistory <- function(turl,

getAllCommentHistory <- function(turl,
commentNo) {
get_comment_history(turl, commentNo, "all", "df")
news_comment_history(turl, commentNo, "all", "df")
}

#' @importFrom purrr when
#' @importFrom httr2 req_perform
get_comment_history <- function(turl,
news_comment_history <- function(turl,
commentNo,
count = 10,
type = c("df", "list")) {
Expand Down
44 changes: 28 additions & 16 deletions R/getContent.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,22 @@
#' @importFrom rvest html_nodes html_text html_attr
#' @examples
#' \dontrun{
#' getContent("https://n.news.naver.com/mnews/article/214/0001195110?sid=103")
#' news_content_("https://n.news.naver.com/mnews/article/214/0001195110?sid=103")
#' }
getContent <- function(turl,
col = c("url",
"original_url",
"section",
"datetime",
"edittime",
"press",
"title",
"body",
"value")) {
news_content(turl, col)
}

getContent <-
news_content <-
function(turl,
col = c("url",
"original_url",
Expand Down Expand Up @@ -65,13 +77,13 @@ getContent <-
}
}
if (value) {
original_url <- getOriginalUrl(html_obj)
title <- getContentTitle(html_obj)
datetime <- getContentDatetime(html_obj)
edittime <- getContentEditDatetime(html_obj)
press <- getContentPress(html_obj)
body <- getContentBody(html_obj)
section <- getSection(turl)
original_url <- news_content_original_url(html_obj)
title <- news_content_title(html_obj)
datetime <- news_content_datetime(html_obj)
edittime <- news_content_edit_datetime(html_obj)
press <- news_content_press(html_obj)
body <- news_content_body(html_obj)
section <- news_content_section(turl)
}

if (length(edittime) == 0) {
Expand All @@ -91,7 +103,7 @@ getContent <-
return(newsInfo[, col])
}

getContentTitle <-
news_content_title <-
function(html_obj,
title_node_info = "h2.media_end_head_headline",
title_attr = "") {
Expand All @@ -104,7 +116,7 @@ getContentTitle <-
}


getContentDatetime <-
news_content_datetime <-
function(html_obj,
datetime_node_info = "span._ARTICLE_DATE_TIME",
datetime_attr = "data-date-time") {
Expand All @@ -116,7 +128,7 @@ getContentDatetime <-
as.POSIXct(datetime, tz = "Asia/Seoul")
}

getContentEditDatetime <-
news_content_edit_datetime <-
function(html_obj,
datetime_node_info = "span._ARTICLE_MODIFY_DATE_TIME",
datetime_attr = "data-modify-date-time") {
Expand All @@ -128,7 +140,7 @@ getContentEditDatetime <-
as.POSIXct(datetime, tz = "Asia/Seoul")
}

getContentPress <-
news_content_press <-
function(html_obj,
press_node_info = "div.media_end_head_top a img",
press_attr = "title") {
Expand All @@ -140,7 +152,7 @@ getContentPress <-
return(press[1])
}

getContentBody <-
news_content_body <-
function(html_obj,
body_node_info = "div#dic_area",
body_attr = "") {
Expand All @@ -153,7 +165,7 @@ getContentBody <-
return(body)
}

getOriginalUrl <- function(html_obj,
news_content_original_url <- function(html_obj,
origin_url_node_info = "a.media_end_head_origin_link",
origin_url_attr = "href") {
node <- rvest::html_nodes(html_obj, origin_url_node_info)
Expand All @@ -166,7 +178,7 @@ getOriginalUrl <- function(html_obj,
}

#' @importFrom httr2 url_parse
getSection <- function(turl) {
news_content_section <- function(turl) {
if (is.null(httr2::url_parse(turl)$query$sid)) {
return(NA)
}
Expand Down
4 changes: 3 additions & 1 deletion R/getMaxPageNum.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
#' \dontrun{
#' getMaxPageNum("https://news.naver.com/main/list.naver?mode=LS2D&mid=shm&sid1=103&sid2=376")
#' }

getMaxPageNum <- function(turl, max = 100) {
news_max_page_num(turl, max)
}
news_max_page_num <- function(turl, max = 100) {
httr2::request(turl) %>%
httr2::req_url_query(page = max) %>%
httr2::req_method("GET") %>%
Expand Down
7 changes: 6 additions & 1 deletion R/getUrlList.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@
#' getUrlList("https://news.naver.com/main/list.naver?mode=LS2D&mid=shm&sid1=103&sid2=376")
#' }

getUrlList <-
getUrlList <- function(turl,
col = c("titles", "links")) {
news_urls_from_list(turl, col)
}

news_urls_from_list <-
function(turl,
col = c("titles", "links")) {

Expand Down
Binary file modified R/sysdata.rda
Binary file not shown.
6 changes: 0 additions & 6 deletions data-raw/news_category.R

This file was deleted.

6 changes: 6 additions & 0 deletions data-raw/news_category_data.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## code to prepare `news_category` dataset goes here
library(N2H4)

news_category_data <- getCategory(fresh = TRUE)

usethis::use_data(news_category_data, overwrite = TRUE, internal = TRUE)
2 changes: 1 addition & 1 deletion man/getContent.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testthat/test-func.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ test_that("passSportsnews", {

test_that("getCategory", {
test <- getCategory()
expect_equal(test, news_category)
expect_equal(test, news_category_data)
})

test_that("getCategoryFresh", {
Expand Down