Skip to content

Commit

Permalink
默认以info级别显示log
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxCrazy1101 committed Sep 1, 2022
1 parent df307ef commit 91015b4
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "etrc12306gen"
authors = ["Alex Newton <[email protected]>"]
version = "0.0.1"
version = "0.1.0"
edition = "2021"
license = "MIT OR Apache-2.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
11 changes: 10 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::time;
use std::{env, time};

use clap::{Args, Parser, Subcommand};
use log::debug;
Expand Down Expand Up @@ -26,7 +26,16 @@ pub struct Cli {
}
impl Cli {
pub fn run(&self) -> Result<(), Box<dyn std::error::Error>> {
// 初始化log
let env_log = env::var("RUST_LOG");
let log_level = if let Ok(env_log) = &env_log {
env_log.as_str()
} else {
"info"
};
env::set_var("RUST_LOG", log_level);
pretty_env_logger::init();

let mut builder = Client::builder()
.cookie_store(true)
.timeout(time::Duration::from_secs(7));
Expand Down
2 changes: 1 addition & 1 deletion src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3257,4 +3257,4 @@ pub static ref STATION_CODE: HashMap<&'static str, &'static str> =[
("漾濞" , "AVM"),
("永平县" , "APM"),
].iter().cloned().collect();
}
}
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ pub mod cli;
mod consts;
pub mod parse;
pub mod pyetgr;
mod utils;
mod utils;
7 changes: 4 additions & 3 deletions src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ pub fn parse_line(
from_value(from_slice::<serde_json::Value>(&data)?["line"]["stations"].clone())?;
debug!("开始读取Cookie");
let mut cookie: Vec<u8> = vec![];
match OpenOptions::new()
if OpenOptions::new()
.create(true)
.write(true)
.read(true)
.open(&"./cookie.txt")
.expect("创建cookie.txt文件失败")
.read_to_end(&mut cookie)
.expect("读取失败cookie.txt文件失败")
== 0
{
0 => panic!("读取cookie.txt失败, 文件为空,请填入cookie后再使用"),
_ => (),
panic!("读取cookie.txt失败, 文件为空,请填入cookie后再使用");
}
let cookie = String::from_utf8(cookie)?;
debug!("加载Cookie成功");
Expand Down Expand Up @@ -226,5 +226,6 @@ pub fn parse_train(
train_history.push(train_number.0);
train_history.push(train_number.1);
}
info!("获取时刻表任务完成");
Ok(())
}

0 comments on commit 91015b4

Please sign in to comment.