An open API service indexing awesome lists of open source software.

https://github.com/seabbs/stacktweetbot

Tools for quickly and easily creating twitter StackOverflow bots
https://github.com/seabbs/stacktweetbot

bot r rpackage rstats stackoverflow stackoverflow-questions twitter

Last synced: 11 months ago
JSON representation

Tools for quickly and easily creating twitter StackOverflow bots

Awesome Lists containing this project

README

          

---
output: github_document
---

```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figure/"
)
```

# Tools to Make a Stack Overflow Twitter Bot

[![lifecycle](https://img.shields.io/badge/lifecycle-stable-green.svg)](https://www.tidyverse.org/lifecycle/#stable)
[![Travis build status](https://travis-ci.org/seabbs/StackTweetBot.svg?branch=master)](https://travis-ci.org/seabbs/StackTweetBot)
[![AppVeyor build status](https://ci.appveyor.com/api/projects/status/fxe1jxdykm5hvn1m?svg=true)](https://ci.appveyor.com/project/seabbs/stacktweetbot)
[![Coverage status](https://codecov.io/gh/seabbs/StackTweetBot/branch/master/graph/badge.svg)](https://codecov.io/github/seabbs/StackTweetBot?branch=master)

The aim of this package is to allow for easy creation of Stack Overflow twitter bots. It provides a wrapper around functionality from [`rtweet`](http://rtweet.info/) and [`stackr`](https://github.com/dgrtwo/stackr). It was inspired by the [tidyverse tweets bot](https://github.com/wjakethompson/tidyverse-tweets/blob/master/tidyversetweets.R) by [Jake Thompson](https://www.wjakethompson.com/), from which large amounts of code has been adapted. For a working example of a bot built with this package see [h2o tweets bot](https://twitter.com/h2o_tweets), or [here](https://github.com/seabbs/h2o_tweets) for the code.

## Installation

Install the development version from GitHub:

```{r gh-installation, eval = FALSE}
# install.packages("devtools")
devtools::install_github("seabbs/StackTweetBot")
```

To schedule the bot you will either need to install `cronR` (if on Linux or Mac) with,

```{r, eval = FALSE}
install.packages("cronR")
```

or taskscheduler (if on windows) with,

```{r, eval = FALSE}
install.packages("taskscheduleR")
```

## Quick start

1. Load the package

```{r load-package}
library(StackTweetBot)
```

2. Set up your bots [Twitter](https://twitter.com/) account - making it clear it is a bot!

3. Set up access to the Twitter API with,

```{r set-up-twitter}
add_twitter_api()
```

4. Set up access to the Stack Overflow API. This is required to increase your daily rate limit from 300 to 10,000.

```{r set-up-stack}
add_stack_api()
```

5. Check you have correctly set up your API access (restart your r session first).

```{r check-api, eval = FALSE}
add_twitter_api()
add_stack_api()
```

5. Set up and schedule the twitter bot, settting the tags to look for and to exclude. Schedule the bot using `schedule = TRUE`, with the arguements to use to define the update time being platform dependent, see `?set_up_stack_tweet_bot` for details. To allow posting set `post = TRUE`, and to save the bot to a permanent directory (so that it will run after your R session has ended) set the directory with `dir`.

```{r schedule-twitter-bot}
set_up_stack_tweet_bot(extracted_tags = "ggplot2",
excluded_tags = "python",
time_window = 60,
add_process_fn = NULL,
hashtags = "rstats",
run = TRUE,
schedule = FALSE,
save = TRUE,
post = FALSE,
dir = NULL,
verbose = TRUE,
frequency = "hourly")
```

6. Check your bot is running.

```{r, eval = FALSE}
## If using cronR on mac or linux
cronR::cron_ls()
## If using taskscheduleR on windows
taskscheduleR::taskscheduler_ls()
```

## Additional Functionality

File an issue [here](https://github.com/seabbs/StackTweetBot/issues) if there is a feature, that you think is missing from the package, or better yet submit a pull request!

## Docker

This package has been developed in docker based on the `rocker/tidyverse` image, to access the development environment enter the following at the command line (with an active docker daemon running),

```{bash, eval = FALSE}
docker pull seabbs/stacktweetbot
docker run -d -p 8787:8787 -p 1410:1410 -e USER=StackTweetBot -e PASSWORD=StackTweetBot --name StackTweetBot seabbs/stacktweetbot
```

The rstudio client can be accessed on port `8787` at `localhost` (or your machines ip). The default username isStackTweetBot and the default password is StackTweetBot. The docker file comes reloaded with `cronR` and therefore may also be used as a staging environment for your twitter bot.