summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNamilskyy <alive6863@gmail.com>2025-03-25 22:20:05 +0300
committerNamilskyy <alive6863@gmail.com>2025-03-25 22:20:26 +0300
commite687e9bd48ce383894fd499595fc25c2dd8ca024 (patch)
tree45fb75296303dabe37f938d8f46e02c707eba485 /src
parentb581af3a76cba646ec58776fcfcca5821bf56221 (diff)
Fixed errors and bugs.
Diffstat (limited to 'src')
-rw-r--r--src/configmanager.rs40
-rw-r--r--src/main.rs25
-rw-r--r--src/parser.rs23
3 files changed, 29 insertions, 59 deletions
diff --git a/src/configmanager.rs b/src/configmanager.rs
index fb8ccc1..0bbbb73 100644
--- a/src/configmanager.rs
+++ b/src/configmanager.rs
@@ -3,25 +3,23 @@ use serde::Deserialize;
use dirs::home_dir;
use std::path::PathBuf;
-impl WeatherFetch{
-#[derive(Deserialize)]
+#[derive(Debug, Deserialize)]
pub struct Config {
- lat: String, //Latitude, decimal (-90; 90)
- lon: String, //Longitude, decimal (-180; 180)
- exclude: String, //By using this parameter you can exclude some parts of the weather
- appid: String, //Your OpenWeatherMap API key
- lang: String, //Output language
- units: String, //Units of measurement
- cache: bool, //Cacheing next Weather to dont use internet in next call
- rain: String, //Path to rain image (png/jpg) or ASCII art int .txt
- sunny: String, //Path to sunny image (png/jpg) or ASCII art int .txt
- snowy: String,
+ pub lat: String,
+ pub lon: String,
+ pub exclude: String,
+ pub appid: String,
+ pub lang: String,
+ pub units: String,
+ pub cache: bool,
+ pub rain: String,
+ pub sunny: String,
+ pub snowy: String,
}
- //More info: OpenWeatherMap.org/api/one-call3
-impl Config{
+impl Config {
pub fn load() -> Result<Self, Box<dyn std::error::Error>> {
- let mut path = home_dir().ok_or("Не удалось найти домашнюю директорию")?;
+ let mut path = home_dir().ok_or("Home directory not found")?;
path.push(".config/WeatherFetch/Config.toml");
let config_str = fs::read_to_string(path)?;
@@ -30,14 +28,10 @@ impl Config{
}
}
-pub fn handle_config(config: &Config) -> Result<(), Box<dyn std::error::Error>> {
- // Пока недоделано
+pub fn handle_config(_config: &Config) -> Result<(), Box<dyn std::error::Error>> {
Ok(())
}
-pub fn gen_standart_conf() {
-
-}
-
-}
-
+pub fn gen_standard_conf() {
+ // TODO: Implement
+} \ No newline at end of file
diff --git a/src/main.rs b/src/main.rs
index 568ef9a..4f15b56 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,19 +1,5 @@
-//In developing 🏗️
-
-use serde::{Serialize, Deserialize};
-use std::{env, path::Path};
-use clap::{Arg, Command};
-use termimage::{Image};
-
-mod parser;
-mod configmanager;
-
-use parser::{parse_weather, Weather};
-use configmanager::{Config, handle_config};
-
-f// main.rs
use clap::{Arg, Command};
-use termimage::Image;
+use termimage;
mod configmanager;
mod parser;
@@ -24,13 +10,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let matches = Command::new("WeatherFetch")
.version("0.1")
.author("Borisov Alexey <arcanetmodl@gmail.com>")
- .about("Weather fetch like fastfetch with image and ASCII art support")
+ .about("Weather fetch with image and ASCII art support")
.arg(Arg::new("image").short('i').long("image").value_name("PATH"))
- .arg(Arg::new("exclude")
- .short('e')
- .long("exclude")
- .value_name("TYPE")
- .possible_values(["current", "minutely", "hourly", "daily", "alerts"]))
+ .arg(Arg::new("exclude").short('e').long("exclude").value_name("TYPE")
+ .value_parser(["current", "minutely", "hourly", "daily", "alerts"]))
.arg(Arg::new("help").short('h').long("help"))
.arg(Arg::new("lat").short('t').long("lat").value_name("LATITUDE"))
.arg(Arg::new("lon").short('n').long("lon").value_name("LONGITUDE"))
diff --git a/src/parser.rs b/src/parser.rs
index f9976e6..e8eff39 100644
--- a/src/parser.rs
+++ b/src/parser.rs
@@ -1,13 +1,8 @@
use reqwest::{Error, Client, get};
use chrono::{DateTime, Utc, prelude::*};
-use serde::{Serialize, Deserealize};
-use std::net::{IpAddr, SocketAddr, UpdSocket};
+use serde::{Serialize, Deserialize};
-mod configmanager;
-
-use configmanager::*;
-
-static ErrBuff: String = reqwest::Error;
+use crate::configmanager::{Config};
//API answer struct`s
#[derive(Debug, Serialize, Deserialize)]
@@ -130,15 +125,15 @@ pub struct Alert {
-pub fn get_location(let coords_args: bool, config: &Config) -> Reslut<(), >{
+pub fn get_location(let coords_args: bool, config: &Config) -> Result<(), String>{
//Get the lat and lon for API call
configmanager::handle_config();
- if configmanager::Config.lat.is_empty() || configmanager::Config.lon.is_empty() && !coords_args{
+ if Config.lat.is_empty() || Config.lon.is_empty() && !coords_args{
println!("No coordinates in configuration file or conf not founded.");
println!("HINT: Try create ~/.config/WeatherFetch/Config.toml");
println!("HINT: And add `lat(<int>)`, `lon(<int>)`.");
- println!("HINT: To get more info check https://openweathermap.org/api/one-call-3")
-
+ println!("HINT: To get more info check https://openweathermap.org/api/one-call-3");
+
Err("No coordinates in config or args.".into())
} else {
Ok(())
@@ -146,8 +141,6 @@ pub fn get_location(let coords_args: bool, config: &Config) -> Reslut<(), >{
}
-
-pub async fn parse_weather(config: &Config) -> Result<(), reqwest::Error> {
-
+pub async fn parse_weather(_config: &Config) -> Result<(), reqwest::Error> {
Ok(())
-} \ No newline at end of file
+}