소스 검색

Add backup_dir argument to backup_tweets()

simplify
Garrick Aden-Buie 7 년 전
부모
커밋
f512da9d2c
2개의 변경된 파일8개의 추가작업 그리고 4개의 파일을 삭제
  1. +4
    -1
      R/tweet_io.R
  2. +4
    -3
      inst/gathertweet.R

+ 4
- 1
R/tweet_io.R 파일 보기

@@ -63,6 +63,7 @@ read_tweets <- function(
#' @export
backup_tweets <- function(
file = getOption("gathertweet.file", "tweets.rds"),
backup_dir = "backups",
lck = NULL
) {
if (!file_exists(file)) return()
@@ -71,7 +72,9 @@ backup_tweets <- function(
on.exit(unlock(lck))
}
stopifnot_locked(lck, message = "Unable to acquire lock on {file}")
file_backup <- path_add(file)
file_backup <- path(fs::path_dir(file), backup_dir, fs::path_file(file))
file_backup <- path_add(file_backup)
fs::dir_create(fs::path_dir(file_backup))
log_info("Backing up tweet file to {file_backup}")
fs::file_copy(file, file_backup)
}

+ 4
- 3
inst/gathertweet.R 파일 보기

@@ -5,7 +5,7 @@

Usage:
gathertweet search [--file=<file>] [options] [--] <terms>...
gathertweet update [--file=<file> --backup --polite --token --debug-args]
gathertweet update [--file=<file> --token=<token> --backup --polite --debug-args]

Arguments
<terms> Search terms. Individual search terms are queried separately,
@@ -32,6 +32,7 @@ Options:
--quiet Disable printing of {rtweet} processing/retrieval messages
--polite Only allow one process (search|update) to run at a time
--backup Create a backup of existing tweet file before writing any new files
--backup-dir <backup_dir> Location for backups, use "" for current directory. [default: backups]
--debug-args Print values of the arguments only
' -> doc

@@ -94,7 +95,7 @@ if (isTRUE(args$search)) {
tweets <- tweets[!duplicated(tweets$status_id), ]

log_info("Gathered {nrow(tweets)} tweets")
if (args$backup) backup_tweets(args$file)
if (args$backup) backup_tweets(args$file, backup_dir = args$backup_dir)
tweets <- save_tweets(tweets, args$file)

log_info("Total of {nrow(tweets)} tweets in {args$file}")
@@ -109,7 +110,7 @@ if (isTRUE(args$search)) {
token = args$token
)
log_debug("Status lookup returned {nrow(tweets)} tweets")
if (args$backup) backup_tweets(args$file)
if (args$backup) backup_tweets(args$file, backup_dir = args$backup_dir)
tweets <- save_tweets(tweets, args$file)
log_debug("Total of {nrow(tweets)} tweets in {args$file}")
log_info("Tweet update complete")

Loading…
취소
저장