diff options
| author | Fuwn <[email protected]> | 2024-06-17 06:35:30 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2024-06-17 06:35:30 -0700 |
| commit | 5559616d7774146275646251fb4183f067fa7e60 (patch) | |
| tree | 3bc2098243bf3d79596df863fb08e7e05f970f1d /src/modules | |
| parent | feat(blogs): update blog descriptions (diff) | |
| download | locus-5559616d7774146275646251fb4183f067fa7e60.tar.xz locus-5559616d7774146275646251fb4183f067fa7e60.zip | |
feat(blogs): remove news
Diffstat (limited to 'src/modules')
| -rw-r--r-- | src/modules/cryptocurrency.rs | 76 | ||||
| -rw-r--r-- | src/modules/stocks.rs | 157 |
2 files changed, 112 insertions, 121 deletions
diff --git a/src/modules/cryptocurrency.rs b/src/modules/cryptocurrency.rs index 755c1fd..4cecfc3 100644 --- a/src/modules/cryptocurrency.rs +++ b/src/modules/cryptocurrency.rs @@ -16,50 +16,46 @@ // Copyright (C) 2022-2022 Fuwn <[email protected]> // SPDX-License-Identifier: GPL-3.0-only -use std::sync::LazyLock; - -use serde::Deserialize; - use crate::{response::success, route::track_mount}; -static REFERRALS: LazyLock<Vec<Referral>> = LazyLock::new(|| { - serde_json::from_str(include_str!( - "../../content/json/cryptocurrency_referrals.json" - )) - .unwrap() -}); +// static REFERRALS: LazyLock<Vec<Referral>> = LazyLock::new(|| { +// serde_json::from_str(include_str!( +// "../../content/json/cryptocurrency_referrals.json" +// )) +// .unwrap() +// }); -#[derive(Deserialize)] -struct Referral { - name: String, - description: String, - url: String, -} +// #[derive(Deserialize)] +// struct Referral { +// name: String, +// description: String, +// url: String, +// } pub fn module(router: &mut windmark::router::Router) { - track_mount( - router, - "/cryptocurrency/referrals", - "Want to start investing in cryptocurrency? Support me by using one of my \ - referral links!", - |context| { - success( - &format!( - "# Referrals\n\n=> /cryptocurrency Home\n=> /stocks Stock Market \ - Dashboard\n\nWant to start investing? Support me by using one of \ - my referral links!\n\n{}", - REFERRALS - .iter() - .map(|r| { - format!("## {}\n\n{}\n\n=> {} {0}", r.name, r.description, r.url) - }) - .collect::<Vec<String>>() - .join("\n") - ), - &context, - ) - }, - ); + // track_mount( + // router, + // "/cryptocurrency/referrals", + // "Want to start investing in cryptocurrency? Support me by using one of my + // \ referral links!", + // |context| { + // success( + // &format!( + // "# Referrals\n\n=> /cryptocurrency Home\n=> /stocks Stock Market \ + // Dashboard\n\nWant to start investing? Support me by using one of \ + // my referral links!\n\n{}", + // REFERRALS + // .iter() + // .map(|r| { + // format!("## {}\n\n{}\n\n=> {} {0}", r.name, r.description, + // r.url) }) + // .collect::<Vec<String>>() + // .join("\n") + // ), + // &context, + // ) + // }, + // ); track_mount( router, @@ -68,7 +64,7 @@ pub fn module(router: &mut windmark::router::Router) { |context| { success( &"# Cryptocurrency\n\n=> /stocks Stock Market Dashboard\n=> \ - /cryptocurrency/referrals Referrals", + /cryptocurrency/referrals Referrals", &context, ) }, diff --git a/src/modules/stocks.rs b/src/modules/stocks.rs index 23a0550..59a482a 100644 --- a/src/modules/stocks.rs +++ b/src/modules/stocks.rs @@ -16,25 +16,24 @@ // Copyright (C) 2022-2022 Fuwn <[email protected]> // SPDX-License-Identifier: GPL-3.0-only -use std::sync::LazyLock; - -use serde::Deserialize; - -use crate::{response::success, route::track_mount}; - -static REFERRALS: LazyLock<Vec<Referral>> = LazyLock::new(|| { - serde_json::from_str(include_str!( - "../../content/json/stock_market_referrals.json" - )) - .unwrap() -}); - -#[derive(Deserialize)] -struct Referral { - name: String, - description: String, - url: String, -} +use { + crate::{response::success, route::track_mount}, + serde::Deserialize, +}; + +// static REFERRALS: LazyLock<Vec<Referral>> = LazyLock::new(|| { +// serde_json::from_str(include_str!( +// "../../content/json/stock_market_referrals.json" +// )) +// .unwrap() +// }); + +// #[derive(Deserialize)] +// struct Referral { +// name: String, +// description: String, +// url: String, +// } #[derive(Deserialize, Debug)] struct Quote { @@ -97,8 +96,8 @@ async fn symbol_to_string(symbol: &str) -> String { quote.as_ref().map_or_else( || { format!( - "An API error has occurred while looking up the {symbol} symbol... Take \ - this up with Finnhub.", + "An API error has occurred while looking up the {symbol} symbol... \ + Take this up with Finnhub.", ) }, |quote| quote.try_to_string().unwrap(), @@ -106,38 +105,37 @@ async fn symbol_to_string(symbol: &str) -> String { } pub fn module(router: &mut windmark::router::Router) { - track_mount( - router, - "/stocks/referrals", - "Want to start investing in the stock market? Support me by using one of \ - my referral links!", - |context| { - success( - &format!( - "# Referrals\n\n=> /stocks Dashboard\n=> /cryptocurrency \ - Cryptocurrency Dashboard\n=> /stocks/telegram Telegram Groups\n=> \ - /stocks/search Search\n\nWant to start investing? Support me by \ - using one of my referral links!\n\n{}", - REFERRALS - .iter() - .map(|r| { - format!("## {}\n\n{}\n\n=> {} {0}", r.name, r.description, r.url) - }) - .collect::<Vec<String>>() - .join("\n") - ), - &context, - ) - }, - ); + // track_mount( + // router, + // "/stocks/referrals", + // "Want to start investing in the stock market? Support me by using one of + // \ my referral links!", + // |context| { + // success( + // &format!( + // "# Referrals\n\n=> /stocks Dashboard\n=> /cryptocurrency \ + // Cryptocurrency Dashboard\n=> /stocks/telegram Telegram Groups\n=> + // \ /stocks/search Search\n\nWant to start investing? Support me + // by \ using one of my referral links!\n\n{}", + // REFERRALS + // .iter() + // .map(|r| { + // format!("## {}\n\n{}\n\n=> {} {0}", r.name, r.description, + // r.url) }) + // .collect::<Vec<String>>() + // .join("\n") + // ), + // &context, + // ) + // }, + // ); track_mount( router, "/stocks", "Explore and search the stock market using Gemini!", - |context| { - async move { - success( + |context| async move { + success( &format!( "# The Stock Market\n\n=> /stocks/search Symbol Search\n=> /stocks/referrals Referrals\n=> /cryptocurrency Cryptocurrency Dashboard\n=> /stocks/telegram Telegram Groups\n\n## Popular \ Symbols\n\n### AAPL\n\n{}\n\n### TSLA\n\n{}\n\n## Credits\n\nFinancial data provided by\n\n=> https://finnhub.io/ Finnhub", @@ -146,7 +144,6 @@ pub fn module(router: &mut windmark::router::Router) { ), &context ) - } }, ); @@ -154,48 +151,46 @@ pub fn module(router: &mut windmark::router::Router) { router, "/stocks/search", "Search for a specific symbol", - |context| { - async move { - let mut symbol = context.url.query().unwrap_or("Symbol Search"); + |context| async move { + let mut symbol = context.url.query().unwrap_or("Symbol Search"); - if symbol.is_empty() { - symbol = "Symbol Search"; - } + if symbol.is_empty() { + symbol = "Symbol Search"; + } - let mut response = format!( - "# {symbol}\n\n=> /stocks Dashboard\n=> /cryptocurrency Cryptocurrency \ - Dashboard\n=> /stocks/telegram Telegram Groups\n=> /stocks/search \ - Search", - ); - - if symbol != "Symbol Search" { - if let Some(query) = context.url.query_pairs().next() { - if query.0 == "action" && query.1 == "go" { - return windmark::response::Response::input( - "Which symbol would you like to explore?", - ); - } - - let symbol = query.0; - - if symbol != "Symbol Search" { - response = format!( - "{}\n\nYou searched for \"{}\"!\n\n## Key Statistics\n\n{}", - response, - symbol, - symbol_to_string(&symbol).await - ); - } + let mut response = format!( + "# {symbol}\n\n=> /stocks Dashboard\n=> /cryptocurrency \ + Cryptocurrency Dashboard\n=> /stocks/telegram Telegram Groups\n=> \ + /stocks/search Search", + ); + + if symbol != "Symbol Search" { + if let Some(query) = context.url.query_pairs().next() { + if query.0 == "action" && query.1 == "go" { + return windmark::response::Response::input( + "Which symbol would you like to explore?", + ); + } + + let symbol = query.0; + + if symbol != "Symbol Search" { + response = format!( + "{}\n\nYou searched for \"{}\"!\n\n## Key Statistics\n\n{}", + response, + symbol, + symbol_to_string(&symbol).await + ); } } + } - success( + success( &format!( "{response}\n\n## Credits\n\nFinancial data provided by\n\n=> https://finnhub.io/ Finnhub", ), &context ) - } }, ); } |