add note for stopping service
This commit is contained in:
parent
7a01944830
commit
042c2684da
1 changed files with 31 additions and 12 deletions
43
src/main.rs
43
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};
|
use chrono::{TimeZone, Utc, NaiveDateTime};
|
||||||
|
@ -63,8 +63,12 @@ impl Date {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[get("/")]
|
||||||
|
fn index() -> String {
|
||||||
|
return "因為RSS來源提供的格式屢屢除錯,致常判讀錯誤,故此程式暫停運作。不便之處敬請見諒".to_string();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
#[get("/<stock_id>/json")]
|
#[get("/<stock_id>/json")]
|
||||||
fn get_tw_stock_json(stock_id: String) -> String {
|
fn get_tw_stock_json(stock_id: String) -> String {
|
||||||
let response_body = get_stock_data(stock_id.as_str(), Date::Day(1), Date::YearToDate);
|
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);
|
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());
|
let rss_xml = get_rss_data(stock_id.as_str());
|
||||||
|
|
||||||
|
println!("~~~{:}", rss_xml);
|
||||||
|
|
||||||
//let rss_xml = fs::read_to_string("/tmp/a.rss")
|
//let rss_xml = fs::read_to_string("/tmp/a.rss")
|
||||||
// .expect("Should have been able to read the file");
|
// .expect("Should have been able to read the file");
|
||||||
|
|
||||||
let rss_parsed = parser::parse(rss_xml.as_bytes()).unwrap();
|
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);
|
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 response_json: Value = serde_json::from_str(response_body.as_str()).unwrap();
|
||||||
|
|
||||||
let mut stock_main_data = tw_stock_process_json(&response_json);
|
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<String>>) ->
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_rss_data(stock_id : &str) -> String{
|
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
|
stock_id
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let res = get_url_data(&url);
|
||||||
|
println!("{:}", res);
|
||||||
return get_url_data(&url);
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_stock_data(stock_id: &str, interval: Date, range: Date) -> String {
|
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
|
stock_id, intrval_str, range_str
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let res = get_url_data(&url);
|
||||||
|
println!("{:}", res);
|
||||||
return get_url_data(&url);
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_url_data(url : &String) -> String{
|
fn get_url_data(url : &String) -> String{
|
||||||
|
@ -288,6 +297,8 @@ let mut response = String::new();
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
curl_transfer.perform().unwrap();
|
curl_transfer.perform().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -297,9 +308,17 @@ return response.clone();
|
||||||
|
|
||||||
#[launch]
|
#[launch]
|
||||||
fn rocket() -> Rocket<Build> {
|
fn rocket() -> Rocket<Build> {
|
||||||
// rocket::ignite().mount("/", routes![index]).launch();
|
//rocket::ignite().mount("/", routes![index]).launch();
|
||||||
rocket::build().attach(Template::fairing())
|
rocket::build().attach(Template::fairing())
|
||||||
.mount("/tw", routes![get_tw_stock, get_tw_stock_json])
|
.mount("/tw", routes![get_tw_stock, get_tw_stock_json])
|
||||||
|
|
||||||
|
|
||||||
|
}*/
|
||||||
|
|
||||||
|
#[launch]
|
||||||
|
fn rocket() -> Rocket<Build> {
|
||||||
|
rocket::build().mount("/", routes![index])
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue