-
Notifications
You must be signed in to change notification settings - Fork 0
/
D1_RunBot.R
57 lines (43 loc) · 1.59 KB
/
D1_RunBot.R
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
#####
# Datasaurs
#####
library(tidyverse)
library(twitteR)
# setwd("C:\Users\Ryan\Documents\808Projects\Datasaurs")
cod_all <- readRDS("BotInputs/D1_CauseOfDeath.RDS")
dino_info <- read.csv("BotInputs/DatasaurList.csv", stringsAsFactors = F)
source("D1_Functions.R")
source("D1_ColorsPatterns.R")
#Datasaur function will go here...
# Set up Twitter API
api_keys <- read.csv("BotInputs/API.csv", stringsAsFactors = FALSE)
setup_twitter_oauth(consumer_key = api_keys$consumer_key,
consumer_secret = api_keys$consumer_secret,
access_token = api_keys$access_token,
access_secret = api_keys$access_secret)
#Check for a special tweet count and set a pattern for that...
# I'd like this to be in the choose_pattern() function, but probably should keep API stuff here
tweet_data <- getUser("Datasaurs")
#2 non-datasaur tweets, +1 for this tweet
next_tweet_number <- (tweet_data$getStatusesCount() - 5 + 1)
dino <- if(months.Date(Sys.Date()) == "July" && lubridate::day(Sys.Date()) >= 25 && lubridate::day(Sys.Date()) <= 28){
dino_info %>%
filter(Family == "Shark") %>%
pull(Fauna) %>%
sample(1)
} else if(Sys.Date() %in% c("2019-11-28", "2020-11-26", "2021-11-25")){
dino <- "Meleagris"
} else {
sample(dino_info$Fauna, 1)
}
datasaur <- dino %>%
naked_datasaur() %>%
skin_datasaur(next_tweet_number %>% choose_pattern()) %>%
wiki_datasaur() %>%
plot_datasaur(version_num = "1.1.2") %>%
text_datasaur()
###
#TWEET IT!
###
updateStatus(datasaur$twitter_text, mediaPath = datasaur$filename,
bypassCharLimit=T)