-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathREADME.Rmd
136 lines (98 loc) · 3.16 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
cache = FALSE,
comment = "",
prompt = TRUE,
fig.path = "man/figures/README-",
out.width = "100%"
)
if (dir.exists(".tmp")) unlink(".tmp", recursive = TRUE)
dir.create(".tmp/rstats", recursive = TRUE, showWarnings = FALSE)
knitr::opts_knit$set(root.dir = ".tmp/rstats")
```
[rtweet]: https://rtweet.info
[cron]: https://en.wikipedia.org/wiki/Cron
<h1 style="font-weight: normal;">gathe<strong>rtweet</strong></h1>
The goal of gathertweet is to provide a simple command line utility that wraps key functions from [rtweet].
The magic of **gathertweet** is that it grants you the power to **quickly set up twitter monitoring and tweet gathering** while saving you from the pain of **writing a bunch of boilerplate code** to
- save new tweets without losing previously collected tweets,
- join multiple searches,
- update tweet stats,
- simplify stored tweets,
- schedule easily with [cron],
- and more...
gathe**rtweet** is a thin wrapper around [rtweet], the excellent R interface to Twitter written by [Mike Kearney](https://mikewk.com/).
If you use gathertweet, please ensure that you [cite rtweet directly](https://rtweet.info/authors.html).
```{r}
citation("rtweet")
```
## Installation
This is a work in progress and may not work well for you yet.
But you are welcome to install **gathertweet** and try it out.
```r
# install.packages("remotes")
remotes::install_github("gadenbuie/gathertweet")
```
Once you've installed the package, you need to run
```r
gathertweet::install_gathertweet()
```
which adds `gathertweet` to `/usr/local/bin` as a symlink (you can adjust where this link is created in `install_gathertweet()`).
If you need admin rights to install, try
```
sudo Rscript -e "gathertweet::install_gathertweet()"
```
from the command line.
## Example
### Use gathertweet from the command line
Create a directory to store tweets
```bash
mkdir rstats
cd rstats
```
```{r include=FALSE}
knitr::opts_knit$set(root.dir = ".tmp/rstats")
```
Get 100 #rstats tweets
```{bash}
gathertweet search --n 100 --quiet "#rstats"
```
Get more tweets, automatically starting from end of the last search
```{r include=FALSE}
Sys.sleep(60)
```
```{bash}
gathertweet search --n 100 --quiet "#rstats"
```
Update the stored data about those #rstats tweets
```{bash}
gathertweet update
```
```{bash}
ls -lh
```
Gather user timelines
```{bash}
gathertweet timeline hadleywickham jennybryan dataandme
```
### Schedule tweet gathering using cron
The primary use case of gathertweet is to make it easy to set up [cron] to periodically gather tweets.
Here's a simple example to download all tweets matching the search term `rstats OR tidyverse` every night at midnight.
The tweets are stored, by default, in `tweets.rds` in `~/rstats-tweets`.
```bash
crontab -e
# m h dom mon dow command
0 0 * * * (cd ~/rstats-tweets && ~/bin/gathertweet search --polite 'rstats OR tidyverse' >>gathertweet.log)
```
## Documentation
```bash
> gathertweet --help
```
```{bash gathertweet_help, echo=FALSE}
../../inst/gathertweet.R --help
```