Created
March 25, 2018 19:45
-
-
Save imjakedaniels/41964688f2b4b6874d5b7c99f198c80e to your computer and use it in GitHub Desktop.
TwitterBot - https://twitter.com/LookOutCanada
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
title: "TwitterBot" | |
author: "Jake" | |
date: "March 25, 2018" | |
output: html_document | |
--- | |
```{r} | |
#Packages | |
library(rvest) | |
library(stringr) | |
library(dplyr) | |
library(twitteR) | |
library(rvest) | |
library(tidyverse) | |
library(magrittr) | |
library(knitr) | |
library(lubridate) | |
``` | |
```{r} | |
#Tokens | |
adj <- c("Rude", "Raunchy", "Sexy", "Overt", "Unexpected", "Covert", "Blessed", "Miracle", "Low-budget", "Messy", "Limited", "Redundant", "Fluke", "Fake", "Moderate", "Skewed", "Broken", "Underperforming", "Wretched", "Organic", "Limited", "Overclocked", "Recently discovered") | |
dataword <- c("cluster analysis", "set of negatively correlated variables", "association rule", "data mining pattern", "market shift", "dataset transformation", "fraud detection", "set of unstructured data", "line of python code", "supervised-learning algorithm", "sample bias", "target variable", "input variable", "range of values", "dummy variable", "F-Score", "log-loss results", "evaluation metric", "subset", "dendrogram", "imputation", "population inference", "line of best fit", "correlation", "classifier", "set of product reviews", "ChatBot", "bell-shaped curve", "outlier", "predictor variable", "reinforced-learning algorithm", "type 1 error", "type 2 error") | |
result <- c("destroys", "liberates", "overpowers", "complicates", "nullifies", "disarms", "discredits", "devistates", "tarnishes") | |
canadian_interest <- c("Drake", "Alex Trebek", "Air Canada", "A&W", "Canadian Tire", "Alanis Morissette", "the entire cast of Degrassi", "the plotline for Anne of Green Gables", "The Arcade Fire", "Avril Lavigne", "Bagged Milk", "Beavers", "Beavertails", "Blackberry", "Canada Day", "Canadian Idol", "the CBC", "Chopped Canada", "Chris Hadfield", "Coffee Crisp", "Corner Gas", "David Suzuki", "Deadmau5's career", "Don Cherry", "the word eh", "George Stroumboulopoulos' newest career move", "Gerry Dee", "Hockey Night In Canada", "the JUNO Awards", "Justin Trudeau", "Ketchup Chips", "Kraft Dinner", "Labatt Beer", "Loblaws", "Wayne Gretzky", "Nelly Furtado", "Nickelback", "Pizza Pizza", "Presidents Choice", "Seth Rogen", "Shoppers Drug Mart", "Sir John A. Macdonald", "snowy road conditions", "the rest of Sum 41", "Tim Hortons Timbits", "the reason we say zed instead of zee") | |
outcomes <- c("stockpile resources.", "erase their childhood memories.", "scream into a pillow for hours.", "cling to their loved ones.", "chant the national anthem.", "shovel their driveway for a 4th time as a form of therapy.", "patriotically sacrifice a double-double in their honour.") | |
``` | |
```{r} | |
#Twitter Authenticator -- I CANT SHARE THIS ONE | |
api_key <- "" | |
api_secret <- "" | |
access_token <- "" | |
access_token_secret <- "" | |
setup_twitter_oauth(api_key,api_secret,access_token,access_token_secret) | |
``` | |
```{r} | |
#Generators | |
random_adj <- NULL | |
for(i in 1){ | |
random_adj <- c(random_adj,sample(adj,size=1)) | |
} | |
random_dataword <- NULL | |
for(i in 1){ | |
random_dataword <- c(random_dataword,sample(dataword,size=1)) | |
} | |
random_result <- NULL | |
for(i in 1){ | |
random_result <- c(random_result,sample(result,size=1)) | |
} | |
random_canadian <- NULL | |
for(i in 1){ | |
random_canadian <- c(random_canadian ,sample(canadian_interest,size=1)) | |
} | |
random_outcome <- NULL | |
for(i in 1){ | |
random_outcome <- c(random_outcome ,sample(outcomes,size=1)) | |
} | |
#Tweets | |
temp <- c(random_adj, random_dataword, random_result, random_canadian, "causing Canadians to", random_outcome) | |
tweettxt <- paste(temp,collapse=" ") | |
tweettxt | |
``` | |
```{r} | |
#Send the tweet | |
tweet(tweettxt) | |
``` | |
```{r} | |
#Log the tweet | |
line <- paste( as.character(Sys.time()), tweettxt,sep="\t" ) | |
write(line, file="tweets.log", append=TRUE) | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment