summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.toml11
-rw-r--r--rustfmt.toml41
-rw-r--r--src/Config.toml0
-rw-r--r--src/configmanager.rs24
-rw-r--r--src/main.rs86
-rw-r--r--src/parser.rs141
6 files changed, 303 insertions, 0 deletions
diff --git a/Cargo.toml b/Cargo.toml
new file mode 100644
index 0000000..dade610
--- /dev/null
+++ b/Cargo.toml
@@ -0,0 +1,11 @@
+[package]
+name = "WheatherFetch"
+version = "0.0.1"
+edition = "2021"
+
+[dependencies]
+termimage = "1.2"
+reqwest = "0.12.15"
+chrono = "0.4"
+serde = ""
+tokio = ""
diff --git a/rustfmt.toml b/rustfmt.toml
new file mode 100644
index 0000000..7dc6e87
--- /dev/null
+++ b/rustfmt.toml
@@ -0,0 +1,41 @@
+# Версия Rust edition (2021, 2018, 2015)
+edition = "2021"
+
+# Общие настройки
+max_width = 100 # Максимальная ширина строки
+hard_tabs = false # Использовать пробелы вместо табов
+tab_spaces = 4 # Количество пробелов на таб
+error_on_line_overflow = true # Ошибка при превышении ширины строки
+report_todo = "Always" # Отмечать TODO комментарии
+report_fixme = "Always" # Отмечать FIXME комментарии
+
+# Отступы и выравнивание
+indent_style = "Block" # Стиль отступов ("Block" или "Visual")
+align_enum_variants = true # Выравнивать варианты enum
+align_function_params = false # Выравнивать параметры функций
+
+# Структуры и enum
+struct_lit_single_line = true # Разрешить литералы структур в одну строку
+enum_discrim_align_threshold = 0 # Выравнивать дискриминанты enum
+match_arm_blocks = true # Блоки в руках match
+match_block_trailing_comma = false # Запятая после последнего элемента в match
+
+# Функции и where-клаузы
+fn_args_layout = "Tall" # Параметры функции в несколько строк
+where_single_line = false # Переносить where-клаузы на новую строку
+brace_style = "SameLineWhere" # Расположение фигурных скобок
+
+# Импорты
+group_imports = "StdExternalCrate" # Группировать импорты
+reorder_imports = false # Сортировать импорты по алфавиту
+imports_granularity = "Crate" # Уровень группировки импортов
+
+# Строки и форматирование
+format_strings = true # Автоформатирование строк
+wrap_comments = true # Перенос длинных комментариев
+comment_width = 80 # Ширина комментариев
+chain_width = 60 # Макс. длина цепочки методов перед переносом
+
+# Макросы
+format_macro_matchers = true # Форматировать тело макросов
+format_macro_bodies = true # Форматировать тела макросов
diff --git a/src/Config.toml b/src/Config.toml
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/Config.toml
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<dyn std::error::Error>>{
+ 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<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. 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<Minutely>,
+ pub hourly: Vec<Hourly>,
+ pub daily: Vec<Daily>,
+ pub alerts: Vec<Alert>,
+}
+
+#[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<Weather>,
+}
+
+#[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<Weather>,
+ 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<Weather>,
+ pub clouds: u32,
+ pub pop: f32,
+ pub rain: Option<f32>,
+ 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<String>,
+}
+: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>{
+
+}