knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)
# Copy reference/images to man/images
# reference folder is required to work with pkgdown
if (!dir.exists("man/figures")) {dir.create("man/figures")}
file.copy(list.files("reference/figures", full.names = TRUE),
          "man/figures", overwrite = TRUE)

tweetrbot

R build status

This is package {tweetrbot}: Functions for a Twitter bot.
Current version is 0.0.1

Installation

The list of dependencies required to install this package is: {dplyr}, {knitr}, {magrittr}, {rmarkdown}, {rtweet}.

To install the package, you can run the following script

# install.packages("remotes")
remotes::install_github(repo = "statnmap/tweetrbot")

Example

knitr::include_graphics(path = "reference/figures/fig_tweetrbot_with_func.png")
library(tweetrbot)

This package is presented in a blog post on https://statnmap.com/2019-08-30-create-a-twitter-bot-on-a-raspberry-pi-3-using-r

Run the scripts to retweet a specific hashtag

This is set for a bot. This means that every tweets retrieved from get_and_store() will be retweeted using retweet_and_update() using a loop, with 1 tweet every 600 seconds here. Set to debug=TRUE to avoid really tweeting on Twitter if you want to make some tests.

## Retrieve tweets, store on the drive
get_and_store(query = "#rspatial", n_tweets = 20, dir = ".")
## Tweet regularly and update the table stored on the drive
retweet_and_update(dir = ".", n_tweets = 20, n_limit = 3, sys_sleep = 600, debug = TRUE)
rds_file <- system.file("complete_tweets_rspatial.rds", package = "tweetrbot")
all_tweets <- readRDS(rds_file)
all_tweets

Run the script to retrieve your user information

get_account_info(user = "talk_rspatial")

Post the most retweeted tweet of the month

Get the database gathered with get_and_store() and tweet the top of the month using top_tweets().

rds_file <- system.file("complete_tweets_rspatial.rds", package = "tweetrbot")
all_tweets <- readRDS(rds_file)
# filter on last month
last_month_tweets <- all_tweets %>% filter_month(the_month = 4, the_year = 2020)
# update last month
last_month_updated <- update_data(
  path = rds_file, 
  statuses = last_month_tweets$status_id)
# Get stats of last month tweets
top_tweets(all_tweets = last_month_updated, post_tweet = TRUE, top_number = 5)
output <- all_tweets %>% 
  filter_month(the_month = 4, the_year = 2020) %>% 
  top_tweets(post_tweet = FALSE, top_number = 5)
output$number_tweets
output$number_contributors


statnmap/tweetrbot documentation built on Oct. 22, 2022, 6:25 p.m.