This commit is contained in:
ZockerKatze
2025-04-30 09:32:21 +02:00
commit 60979f2d9c
9 changed files with 1897 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/target

8
.idea/.gitignore generated vendored Normal file
View 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
View 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
View 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
View 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
View 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

File diff suppressed because it is too large Load Diff

12
Cargo.toml Normal file
View 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
View 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(())
}