feat: 程序入口进行数据库迁移,读取全局配置
This commit is contained in:
23
src/main.rs
23
src/main.rs
@@ -1,29 +1,34 @@
|
||||
use bili_sync::bilibili::BiliClient;
|
||||
use bili_sync::core::command::process_favorite;
|
||||
use bili_sync::database::database_connection;
|
||||
use bili_sync::database::{database_connection, migrate_database};
|
||||
use log::error;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> ! {
|
||||
env_logger::init();
|
||||
let mut today = chrono::Local::now().date_naive();
|
||||
let mut bili_client = BiliClient::new(None);
|
||||
let mut anchor = chrono::Local::now().date_naive();
|
||||
let (credential, interval, favorites) = {
|
||||
let config = bili_sync::config::CONFIG.lock().unwrap();
|
||||
(config.credential.clone(), config.interval, config.favorite_list.clone())
|
||||
};
|
||||
let mut bili_client = BiliClient::new(credential);
|
||||
let connection = database_connection().await.unwrap();
|
||||
migrate_database(&connection).await.unwrap();
|
||||
loop {
|
||||
if today != chrono::Local::now().date_naive() {
|
||||
if anchor != chrono::Local::now().date_naive() {
|
||||
if let Err(e) = bili_client.check_refresh().await {
|
||||
error!("Error: {e}");
|
||||
tokio::time::sleep(std::time::Duration::from_secs(600)).await;
|
||||
tokio::time::sleep(std::time::Duration::from_secs(interval)).await;
|
||||
continue;
|
||||
}
|
||||
today = chrono::Local::now().date_naive();
|
||||
anchor = chrono::Local::now().date_naive();
|
||||
}
|
||||
for fid in ["52642258"] {
|
||||
let res = process_favorite(&bili_client, fid, &connection).await;
|
||||
for (fid, path) in &favorites {
|
||||
let res = process_favorite(&bili_client, fid, path, &connection).await;
|
||||
if let Err(e) = res {
|
||||
error!("Error: {e}");
|
||||
}
|
||||
}
|
||||
tokio::time::sleep(std::time::Duration::from_secs(600)).await;
|
||||
tokio::time::sleep(std::time::Duration::from_secs(interval)).await;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user