Assignment_6

Author

Stephen Lynch

The ZenQuotes API gives us quotes from some of the worlds most famous authors. We can use it to generate a random quote of the day for something like a journal or a daily video.

library(httr)
library(jsonlite)
Warning: package 'jsonlite' was built under R version 4.4.3
library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   3.5.1     ✔ tibble    3.2.1
✔ lubridate 1.9.3     ✔ tidyr     1.3.1
✔ purrr     1.0.2     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter()  masks stats::filter()
✖ purrr::flatten() masks jsonlite::flatten()
✖ dplyr::lag()     masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
api_url <- "https://zenquotes.io/api/"

We start the process by building a get_random_quote function which gets the data converting the json storage into a df that’s easier for me to manipulate.

Next we call the Quote, q, and Author, a.

Next we print out the Quote and then the Author.

get_random_quote <- function() {
  
  
  resp <- GET("https://zenquotes.io/api/random")
  
  
  quote_data <- fromJSON(content(resp, "text", encoding = "UTF-8"))
  
  
  quote <- quote_data$q
  author <- quote_data$a
  
  
  print(quote)
  print(author)
  
}
get_random_quote()
[1] "You have the potential for greatness."
[1] "Steve Harvey"