https://github.com/statnmap/tweetrbot
Functions for a Twitter bot
https://github.com/statnmap/tweetrbot
Last synced: 9 months ago
JSON representation
Functions for a Twitter bot
- Host: GitHub
- URL: https://github.com/statnmap/tweetrbot
- Owner: statnmap
- License: other
- Created: 2019-08-30T19:28:03.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2022-10-16T12:40:03.000Z (over 3 years ago)
- Last Synced: 2025-04-19T19:24:55.094Z (about 1 year ago)
- Language: R
- Homepage: https://statnmap.github.io/tweetrbot/
- Size: 1.31 MB
- Stars: 3
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE
Awesome Lists containing this project
README
---
output: github_document
---
```{r, include = FALSE}
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
[](https://github.com/statnmap/tweetrbot/actions)
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
```{r, echo=TRUE, eval=FALSE}
# install.packages("remotes")
remotes::install_github(repo = "statnmap/tweetrbot")
```
## Example
```{r, echo=FALSE, out.width="60%", fig.align='center'}
knitr::include_graphics(path = "reference/figures/fig_tweetrbot_with_func.png")
```
```{r}
library(tweetrbot)
```
This package is presented in a blog post on
### 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.
```{r example, eval=FALSE}
## 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)
```
```{r, echo=FALSE}
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
```{r, eval=FALSE}
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()`.
```{r, eval=FALSE}
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)
```
```{r, echo=FALSE, out.width="45%"}
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
```