Last active
July 19, 2018 20:29
-
-
Save Torvaney/7b6e6fe5e16b9c5fe59b5b1685683ca0 to your computer and use it in GitHub Desktop.
This file contains 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
library(rvest) | |
library(stringr) | |
webpage <- read_html("https://en.wikipedia.org/wiki/Magic_8-Ball") | |
# Find the answers | |
answers <- | |
webpage %>% | |
html_nodes("dd") %>% | |
html_text() %>% | |
str_extract("[A-z].*") | |
# Format them (to copy and paste into function definition) | |
str_c("\"", answers, "\"", collapse = ", ") %>% | |
str_c("c(", ., ")") %>% | |
cat() | |
magic_8_ball <- function() { | |
answers <- c("It is certain", | |
"It is decidedly so", | |
"Without a doubt", | |
"Yes definitely", | |
"You may rely on it", | |
"You can count on it", | |
"As I see it, yes", | |
"Most likely", | |
"Outlook good", | |
"Yes", | |
"Signs point to yes", | |
"Absolutely", | |
"Reply hazy try again", | |
"Ask again later", | |
"Better not tell you now", | |
"Cannot predict now", | |
"Concentrate and ask again", | |
"Don't count on it", | |
"My reply is no", | |
"My sources say no", | |
"Outlook not so good", | |
"Very doubtful", | |
"Chances aren't good") | |
sample(answers, size = 1) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment