From 667a259c981df9f08c49d4fe83fc2f907be06784 Mon Sep 17 00:00:00 2001 From: Namilskyy Date: Mon, 24 Mar 2025 21:42:48 +0300 Subject: Start dev --- src/Config.toml | 0 src/configmanager.rs | 24 +++++++++ src/main.rs | 86 +++++++++++++++++++++++++++++++ src/parser.rs | 141 +++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 251 insertions(+) create mode 100644 src/Config.toml create mode 100644 src/configmanager.rs create mode 100644 src/main.rs create mode 100644 src/parser.rs (limited to 'src') diff --git a/src/Config.toml b/src/Config.toml new file mode 100644 index 0000000..e69de29 diff --git a/src/configmanager.rs b/src/configmanager.rs new file mode 100644 index 0000000..e046aa2 --- /dev/null +++ b/src/configmanager.rs @@ -0,0 +1,24 @@ +use std::fs; +use serde::Deserialize; + +impl WeatherFetch{ +#[derive(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, + //More info: OpenWeatherMap.org/api/one-call3 +} + +pub fn handle_config() -> Result<(), Box>{ + let Config_str = fs::read_to_string("~/.config/WeatherFetch/Config.toml"); + let Config_parse: Config = toml::from_str(&data)?.except(); +} +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..5119def --- /dev/null +++ b/src/main.rs @@ -0,0 +1,86 @@ +//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}; + +fn main() -> Result<(), Box> { + + let matches = Command::new("WeatherFetch") + .version("0.1") + .author("Borisov Alexey ") + .about("Weather fetch like fastfetch with image and ASCII art support. Just useless pet project.") + .arg( + Arg::new("image") + .short("i") + .long("image") + .value_name("PATH") + .help("Path to image file") + .takes_value(true), + ) + .arg( + Arg::new("exclude") + .short("e") + .long("exclude") + .value_name("TYPE") + .possible_values(["current", "minutely", "hourly", "daily", "alerts"]) + .help("Exclude specific weather data type") + .takes_value(true), + ) + .arg( + Arg::new("help") + .short("h") + .long("help") + .help("Print help information") + .takes_value(false), + ) + .arg( + Arg::new(lat) + .short("lt") + .long("lat") + .value_name("TWO DIGITS") + .help("Coordinates for weather API call. Latitude.") + .takes_value(true) + ) + .arg( + Arg::new("lon") + .short("ln") + .long("lon") + .value_name("TWO DIGITS") + .help("Coordinates for weather API call. Latitude.") + .takes_value(true) + ) + .get_matches(); + + + if matches.is_present("help") { + + return Ok(()); + } + + + if let Some(img_path) = matches.value_of("image") { + let img = Image::from_path(img_path)?; + + } + + + if let Some(exclude_type) = matches.value_of("exclude") { + + + } + + + let config = Config::load()?; + handle_config(&config)?; + + Ok(()) +} + diff --git a/src/parser.rs b/src/parser.rs new file mode 100644 index 0000000..37d0885 --- /dev/null +++ b/src/parser.rs @@ -0,0 +1,141 @@ +mod condfigmanager + +use reqwest::{Error, Client, get}; +use chrono::{DateTime, Utc, prelude::*}; +use serde::{Serialize, Deserealize}; +use std::net::{IpAddr, SocketAddr, UpdSocket}; +use tokio; + +static ErrBuff: String = reqwest::Error; + +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Serialize, Deserialize)] +pub struct WeatherData { + pub lat: f64, + pub lon: f64, + pub timezone: String, + pub timezone_offset: i32, + pub current: Current, + pub minutely: Vec, + pub hourly: Vec, + pub daily: Vec, + pub alerts: Vec, +} + +#[derive(Debug, Serialize, Deserialize)] +pub struct Current { + pub dt: u64, + pub sunrise: u64, + pub sunset: u64, + pub temp: f32, + pub feels_like: f32, + pub pressure: u32, + pub humidity: u32, + pub dew_point: f32, + pub uvi: f32, + pub clouds: u32, + pub visibility: u32, + pub wind_speed: f32, + pub wind_deg: u32, + pub wind_gust: f32, + pub weather: Vec, +} + +#[derive(Debug, Serialize, Deserialize)] +pub struct Weather { + pub id: u32, + pub main: String, + pub description: String, + pub icon: String, +} + +#[derive(Debug, Serialize, Deserialize)] +pub struct Minutely { + pub dt: u64, + pub precipitation: f32, +} + +#[derive(Debug, Serialize, Deserialize)] +pub struct Hourly { + pub dt: u64, + pub temp: f32, + pub feels_like: f32, + pub pressure: u32, + pub humidity: u32, + pub dew_point: f32, + pub uvi: f32, + pub clouds: u32, + pub visibility: u32, + pub wind_speed: f32, + pub wind_deg: u32, + pub wind_gust: f32, + pub weather: Vec, + pub pop: f32, +} + +#[derive(Debug, Serialize, Deserialize)] +pub struct Daily { + pub dt: u64, + pub sunrise: u64, + pub sunset: u64, + pub moonrise: u64, + pub moonset: u64, + pub moon_phase: f32, + pub summary: String, + pub temp: Temp, + pub feels_like: FeelsLike, + pub pressure: u32, + pub humidity: u32, + pub dew_point: f32, + pub wind_speed: f32, + pub wind_deg: u32, + pub wind_gust: f32, + pub weather: Vec, + pub clouds: u32, + pub pop: f32, + pub rain: Option, + pub uvi: f32, +} + +#[derive(Debug, Serialize, Deserialize)] +pub struct Temp { + pub day: f32, + pub min: f32, + pub max: f32, + pub night: f32, + pub eve: f32, + pub morn: f32, +} + +#[derive(Debug, Serialize, Deserialize)] +pub struct FeelsLike { + pub day: f32, + pub night: f32, + pub eve: f32, + pub morn: f32, +} + +#[derive(Debug, Serialize, Deserialize)] +pub struct Alert { + pub sender_name: String, + pub event: String, + pub start: u64, + pub end: u64, + pub description: String, + pub tags: Vec, +} +:qa + + +:q + +async fn get_location(let ip: String) -> Reslut<(), >{ + let ip: String = reqwest::get("https://api.ipify.org").await?.text.await?; +} + + +#[tokio::main] +async pub fn parse_wheather() -> Result<(), Error>{ + +} -- cgit v1.2.3