added random quote generator files

This commit is contained in:
Dom Sec 2023-03-22 20:21:36 -04:00 committed by GitHub
parent 7f3d8a0635
commit 0ad9f98721
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 1148 additions and 0 deletions

1114
random_quote/Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

13
random_quote/Cargo.toml Normal file
View File

@ -0,0 +1,13 @@
[package]
name = "random_quote"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
json = "0.12.4"
serde_json = "1.0.94"
reqwest = { version = "0.11", features = ["json", "blocking"] }
tokio = { version = "1", features = ["full"] }
serde = { version = "1.0.130", features = ["derive"] }

21
random_quote/src/main.rs Normal file
View File

@ -0,0 +1,21 @@
use serde::{Deserialize, Serialize};
use reqwest::blocking::get;
pub type Response = Vec<Quote>;
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Quote {
pub q: String,
pub a: String,
pub h: String,
}
fn main() {
let res = get("https://zenquotes.io/api/random").unwrap();
let quotes = res.json::<Response>().unwrap();
for quote in quotes {
println!("Author: {}", quote.a);
println!("Quote: {}", quote.q);
}
}