fix: 修改get_data_from500_com返回值

This commit is contained in:
chenwj 2024-07-30 15:02:55 +08:00
parent 95d8f7de3b
commit 9f99c2a2b4
2 changed files with 13 additions and 12 deletions

View File

@ -1,6 +1,5 @@
use std::{thread, time::Duration}; use std::{thread, time::Duration};
use chrono::format;
use clokwerk::{Scheduler, TimeUnits, Job}; use clokwerk::{Scheduler, TimeUnits, Job};
use log::{info, error}; use log::{info, error};
@ -19,12 +18,12 @@ fn main() {
let res = get_data_from_500_com("pls").await; let res = get_data_from_500_com("pls").await;
let msg; let msg;
match res { match res {
Ok(_) => { Ok(val) => {
msg = format!("{}: 排列3数据采集完毕", chrono::Local::now().format(fmt)); msg = format!("{}: 排列3数据采集完毕, 最新数据为: {}!", chrono::Local::now().format(fmt), val);
info!("{}", msg); info!("{}", msg);
}, },
Err(e) => { Err(e) => {
msg = format!("{}: 排列3数据采集失败: {}", chrono::Local::now().format(fmt), e); msg = format!("{}: 排列3数据采集失败: {}!", chrono::Local::now().format(fmt), e);
error!("{}", msg); error!("{}", msg);
} }
} }
@ -43,12 +42,12 @@ fn main() {
let res = get_data_from_500_com("plw").await; let res = get_data_from_500_com("plw").await;
let msg; let msg;
match res { match res {
Ok(_) => { Ok(val) => {
msg = format!("{}: 排列5数据采集完毕", chrono::Local::now().format(fmt)); msg = format!("{}: 排列5数据采集完毕, 最新数据为: {}!", chrono::Local::now().format(fmt), val);
info!("{}", msg); info!("{}", msg);
}, },
Err(e) => { Err(e) => {
msg = format!("{}: 排列5数据采集失败: {}", chrono::Local::now().format(fmt), e); msg = format!("{}: 排列5数据采集失败: {}!", chrono::Local::now().format(fmt), e);
error!("{}", msg); error!("{}", msg);
} }
} }
@ -67,12 +66,12 @@ fn main() {
let res = get_data_from_500_com("sd").await; let res = get_data_from_500_com("sd").await;
let msg; let msg;
match res { match res {
Ok(_) => { Ok(val) => {
msg = format!("{}: 福彩3D数据采集完毕", chrono::Local::now().format(fmt)); msg = format!("{}: 福彩3D数据采集完毕, 最新数据为: {}!", chrono::Local::now().format(fmt), val);
info!("{}", msg); info!("{}", msg);
}, },
Err(e) => { Err(e) => {
msg = format!("{}: 福彩3D数据采集失败: {}", chrono::Local::now().format(fmt), e); msg = format!("{}: 福彩3D数据采集失败: {}!", chrono::Local::now().format(fmt), e);
error!("{}", msg); error!("{}", msg);
} }
} }

View File

@ -8,7 +8,7 @@ use sea_orm::{ActiveModelTrait, ActiveValue::Set, ConnectOptions, Database};
use crate::model::{sd, pls, plw}; use crate::model::{sd, pls, plw};
pub async fn get_data_from_500_com(issue_type: &str) -> Result<(), String> { pub async fn get_data_from_500_com(issue_type: &str) -> Result<String, String> {
// 数据库连接操作 // 数据库连接操作
let db_url; let db_url;
@ -53,6 +53,7 @@ pub async fn get_data_from_500_com(issue_type: &str) -> Result<(), String> {
let ball_selector = Selector::parse(r#"li.ball_orange"#).expect("selector error"); let ball_selector = Selector::parse(r#"li.ball_orange"#).expect("selector error");
let ball_iter = html.select(&ball_selector).map(|x| {x.inner_html()}); let ball_iter = html.select(&ball_selector).map(|x| {x.inner_html()});
let ball: String = ball_iter.collect(); let ball: String = ball_iter.collect();
let ret_val = ball.clone();
let numbers : Vec<i32> = ball.chars().map(|c| c.to_digit(10).unwrap() as i32).collect(); let numbers : Vec<i32> = ball.chars().map(|c| c.to_digit(10).unwrap() as i32).collect();
let mut seen = std::collections::HashSet::new(); let mut seen = std::collections::HashSet::new();
@ -134,7 +135,8 @@ pub async fn get_data_from_500_com(issue_type: &str) -> Result<(), String> {
}; };
new_model.insert(&db).await.expect("insert error"); new_model.insert(&db).await.expect("insert error");
} }
Ok(()) // 返回获取的数据
Ok(ret_val)
} else { } else {
Err(String::from("获取数据失败")) Err(String::from("获取数据失败"))
} }