-
Notifications
You must be signed in to change notification settings - Fork 2
/
README.Rmd
98 lines (79 loc) · 3.12 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{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
<!-- badges: start -->
[![R build status](https://github.com/statnmap/tweetrbot/workflows/R-CMD-check/badge.svg)](https://github.com/statnmap/tweetrbot/actions)
<!-- badges: end -->
<!-- description: start -->
This is package {tweetrbot}: Functions for a Twitter bot.
Current version is 0.0.1
<!-- description: end -->
## Installation
<!-- install: start -->
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 <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.
```{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
```