From 3da9c33d143068396c4985741a9987acc2497410 Mon Sep 17 00:00:00 2001 From: Tan Kian-ting Date: Tue, 11 Jul 2023 23:55:11 +0800 Subject: [PATCH] add rss-flow basically --- src/main.rs | 16 +++ templates/tw_stock.html.hbs | 189 +++++++++++++++++++++++++++++++++++- 2 files changed, 202 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index cfa7708..3859630 100644 --- a/src/main.rs +++ b/src/main.rs @@ -113,6 +113,9 @@ fn tw_stock_process_json(response_json : &Value) -> HashMap<&str, Vec>{ #[get("/")] fn get_tw_stock(stock_id: String) -> Template { + let rss_content = get_rss_data(stock_id.as_str()); + println!("{:}", rss_content); + let response_body = get_stock_data(stock_id.as_str(), Date::Day(1), Date::YearToDate); let response_json: Value = serde_json::from_str(response_body.as_str()).unwrap(); @@ -120,6 +123,9 @@ fn get_tw_stock(stock_id: String) -> Template { let mut stock_total_data = tw_stock_process_json(&response_json); stock_total_data.insert("stock_id", vec![stock_id]); + stock_total_data.insert("news", vec![rss_content]); + + let mut stock_total_data_by_date = transverse_stock_data_by_date(stock_total_data.clone()); //let mut stock_total_data_by_date_wrapper = HashMap::new(); @@ -161,6 +167,16 @@ fn transverse_stock_data_by_date(orig_data : HashMap<&str, Vec>) -> } +fn get_rss_data(stock_id : &str) -> String{ + let url = format!( + "https://tw.stock.yahoo.com/rss?s={:}", + stock_id + ); + + + + return get_url_data(&url); +} fn get_stock_data(stock_id: &str, interval: Date, range: Date) -> String { let intrval_str = interval.as_str(); diff --git a/templates/tw_stock.html.hbs b/templates/tw_stock.html.hbs index 2fcfbb5..180de4a 100644 --- a/templates/tw_stock.html.hbs +++ b/templates/tw_stock.html.hbs @@ -15,13 +15,64 @@ padding: 1em 0.6em; border: 1px solid red; } + +#css-table { + display:table; + } +.css-tr { + display: table-row; + } +.css-td { + display: table-cell; + } + + + - +

{{stock_id.0}}

+ (JSON) +
+
+
@@ -40,6 +91,138 @@ {{/each}} -
日期 開盤{{lookup ../volume @index}}
- +
+ +

+
+ 5日
+ 30日
+ 今年迄今
+
+ +
+
{{news.0}}
+
+ + + + \ No newline at end of file -- 2.39.2