From: Tan Kian-ting Date: Mon, 15 Jul 2024 16:01:36 +0000 (+0800) Subject: add note for stopping service X-Git-Url: https://git.kianting.info/?a=commitdiff_plain;h=042c2684da410ee352019bf01ff08aa9ce283dd6;p=taikoothong add note for stopping service --- diff --git a/src/main.rs b/src/main.rs index ef215bc..0a31d55 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,7 +18,7 @@ Free Hong Kong→天安门屠杀→中国言论钳制→中共文字狱→ 如何润到墙外→中国青年失业率真相→历史的伤口→白纸革命→四通桥事件→ 墙内 */ -#![feature(proc_macro_hygiene, decl_macro)] +//#![feature(proc_macro_hygiene, decl_macro)] use chrono::{TimeZone, Utc, NaiveDateTime}; @@ -63,8 +63,12 @@ impl Date { } } } +#[get("/")] +fn index() -> String { + return "因為RSS來源提供的格式屢屢除錯,致常判讀錯誤,故此程式暫停運作。不便之處敬請見諒".to_string(); +} - +/* #[get("//json")] fn get_tw_stock_json(stock_id: String) -> String { let response_body = get_stock_data(stock_id.as_str(), Date::Day(1), Date::YearToDate); @@ -75,7 +79,8 @@ fn get_tw_stock_json(stock_id: String) -> String { let stock_main_data_json = serde_json::json!(stock_main_data); - return stock_main_data_json.to_string(); + //return stock_main_data_json.to_string(); + return "000".to_string(); } @@ -145,13 +150,17 @@ fn get_tw_stock(stock_id: String) -> Template { let rss_xml = get_rss_data(stock_id.as_str()); + println!("~~~{:}", rss_xml); + //let rss_xml = fs::read_to_string("/tmp/a.rss") // .expect("Should have been able to read the file"); let rss_parsed = parser::parse(rss_xml.as_bytes()).unwrap(); - + println!("qqqq"); let response_body = get_stock_data(stock_id.as_str(), Date::Day(1), Date::YearToDate); + + println!("rrrr"); let response_json: Value = serde_json::from_str(response_body.as_str()).unwrap(); let mut stock_main_data = tw_stock_process_json(&response_json); @@ -244,13 +253,13 @@ 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={:}", + let url = format!("https://tw.stock.yahoo.com/rss?s={:}.TW", stock_id ); - - - return get_url_data(&url); + let res = get_url_data(&url); + println!("{:}", res); + return res; } fn get_stock_data(stock_id: &str, interval: Date, range: Date) -> String { @@ -263,9 +272,9 @@ fn get_stock_data(stock_id: &str, interval: Date, range: Date) -> String { stock_id, intrval_str, range_str ); - - - return get_url_data(&url); + let res = get_url_data(&url); + println!("{:}", res); + return res; } fn get_url_data(url : &String) -> String{ @@ -288,6 +297,8 @@ let mut response = String::new(); }) .unwrap(); + + curl_transfer.perform().unwrap(); } @@ -297,9 +308,17 @@ return response.clone(); #[launch] fn rocket() -> Rocket { - // rocket::ignite().mount("/", routes![index]).launch(); + //rocket::ignite().mount("/", routes![index]).launch(); rocket::build().attach(Template::fairing()) .mount("/tw", routes![get_tw_stock, get_tw_stock_json]) +}*/ + +#[launch] +fn rocket() -> Rocket { + rocket::build().mount("/", routes![index]) + + } +