initial
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/target
|
||||
8
.idea/.gitignore
generated
vendored
Normal file
8
.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
11
.idea/bible_random.iml
generated
Normal file
11
.idea/bible_random.iml
generated
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="EMPTY_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
10
.idea/material_theme_project_new.xml
generated
Normal file
10
.idea/material_theme_project_new.xml
generated
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="MaterialThemeProjectNewConfig">
|
||||
<option name="metadata">
|
||||
<MTProjectMetadataState>
|
||||
<option name="userId" value="ee548a4:19685882df7:-7ff2" />
|
||||
</MTProjectMetadataState>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
||||
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/bible_random.iml" filepath="$PROJECT_DIR$/.idea/bible_random.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
1764
Cargo.lock
generated
Normal file
1764
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
12
Cargo.toml
Normal file
12
Cargo.toml
Normal file
@@ -0,0 +1,12 @@
|
||||
[package]
|
||||
name = "bible_random"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
authors = ["Bible CLI App"]
|
||||
|
||||
[dependencies]
|
||||
reqwest = { version = "0.12.15", features = ["json"] }
|
||||
tokio = { version = "1", features = ["full"] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
clap = "4.4"
|
||||
colored = "3.0.0"
|
||||
77
src/main.rs
Normal file
77
src/main.rs
Normal file
@@ -0,0 +1,77 @@
|
||||
use clap::Command;
|
||||
use colored::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::error::Error;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
struct BibleVerse {
|
||||
translation: Translation,
|
||||
random_verse: RandomVerse,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
struct Translation {
|
||||
identifier: String,
|
||||
name: String,
|
||||
language: String,
|
||||
language_code: String,
|
||||
license: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
struct RandomVerse {
|
||||
book_id: String,
|
||||
book: String,
|
||||
chapter: i32,
|
||||
verse: i32,
|
||||
text: String,
|
||||
}
|
||||
|
||||
async fn fetch_random_verse() -> Result<BibleVerse, Box<dyn Error>> {
|
||||
let url = "https://bible-api.com/data/web/random";
|
||||
let verse = reqwest::get(url).await?.json::<BibleVerse>().await?;
|
||||
Ok(verse)
|
||||
}
|
||||
|
||||
fn display_verse(verse: &BibleVerse) {
|
||||
println!("{}", "═".color("cyan").repeat(60));
|
||||
|
||||
// Create a reference string like "Book chapter:verse"
|
||||
let reference = format!("{} {}:{}",
|
||||
verse.random_verse.book,
|
||||
verse.random_verse.chapter,
|
||||
verse.random_verse.verse);
|
||||
|
||||
println!("{}", reference.bold().color("yellow"));
|
||||
println!();
|
||||
println!("{}", verse.random_verse.text.trim());
|
||||
println!();
|
||||
println!("─ {} ({}) [{}]",
|
||||
verse.translation.name.italic().color("green"),
|
||||
verse.translation.identifier.italic(),
|
||||
verse.translation.language);
|
||||
println!("{}", "═".color("cyan").repeat(60));
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn Error>> {
|
||||
let _matches = Command::new("Bible Verse")
|
||||
.version("1.0")
|
||||
.author("BibleVerse")
|
||||
.about("Fetches random Bible verses")
|
||||
.get_matches();
|
||||
|
||||
println!("Fetching a random Bible verse...");
|
||||
|
||||
match fetch_random_verse().await {
|
||||
Ok(verse) => {
|
||||
display_verse(&verse);
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("{} {}", "Error:".bold().color("red"), e);
|
||||
eprintln!("Try checking your internet connection or the API endpoint.");
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user