瀏覽代碼

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 查看文件

#' @export #' @export
backup_tweets <- function( backup_tweets <- function(
file = getOption("gathertweet.file", "tweets.rds"), file = getOption("gathertweet.file", "tweets.rds"),
backup_dir = "backups",
lck = NULL lck = NULL
) { ) {
if (!file_exists(file)) return() if (!file_exists(file)) return()
on.exit(unlock(lck)) on.exit(unlock(lck))
} }
stopifnot_locked(lck, message = "Unable to acquire lock on {file}") 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}") log_info("Backing up tweet file to {file_backup}")
fs::file_copy(file, file_backup) fs::file_copy(file, file_backup)
} }

+ 4
- 3
inst/gathertweet.R 查看文件



Usage: Usage:
gathertweet search [--file=<file>] [options] [--] <terms>... 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 Arguments
<terms> Search terms. Individual search terms are queried separately, <terms> Search terms. Individual search terms are queried separately,
--quiet Disable printing of {rtweet} processing/retrieval messages --quiet Disable printing of {rtweet} processing/retrieval messages
--polite Only allow one process (search|update) to run at a time --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 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 --debug-args Print values of the arguments only
' -> doc ' -> doc


tweets <- tweets[!duplicated(tweets$status_id), ] tweets <- tweets[!duplicated(tweets$status_id), ]


log_info("Gathered {nrow(tweets)} tweets") 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) tweets <- save_tweets(tweets, args$file)


log_info("Total of {nrow(tweets)} tweets in {args$file}") log_info("Total of {nrow(tweets)} tweets in {args$file}")
token = args$token token = args$token
) )
log_debug("Status lookup returned {nrow(tweets)} tweets") 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) tweets <- save_tweets(tweets, args$file)
log_debug("Total of {nrow(tweets)} tweets in {args$file}") log_debug("Total of {nrow(tweets)} tweets in {args$file}")
log_info("Tweet update complete") log_info("Tweet update complete")

Loading…
取消
儲存