mirror of
https://github.com/amtoaer/bili-sync.git
synced 2026-08-28 03:28:05 +08:00
feat: 程序入口进行数据库迁移,读取全局配置
This commit is contained in:
+14
-9
@@ -1,29 +1,34 @@
|
|||||||
use bili_sync::bilibili::BiliClient;
|
use bili_sync::bilibili::BiliClient;
|
||||||
use bili_sync::core::command::process_favorite;
|
use bili_sync::core::command::process_favorite;
|
||||||
use bili_sync::database::database_connection;
|
use bili_sync::database::{database_connection, migrate_database};
|
||||||
use log::error;
|
use log::error;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> ! {
|
async fn main() -> ! {
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
let mut today = chrono::Local::now().date_naive();
|
let mut anchor = chrono::Local::now().date_naive();
|
||||||
let mut bili_client = BiliClient::new(None);
|
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();
|
let connection = database_connection().await.unwrap();
|
||||||
|
migrate_database(&connection).await.unwrap();
|
||||||
loop {
|
loop {
|
||||||
if today != chrono::Local::now().date_naive() {
|
if anchor != chrono::Local::now().date_naive() {
|
||||||
if let Err(e) = bili_client.check_refresh().await {
|
if let Err(e) = bili_client.check_refresh().await {
|
||||||
error!("Error: {e}");
|
error!("Error: {e}");
|
||||||
tokio::time::sleep(std::time::Duration::from_secs(600)).await;
|
tokio::time::sleep(std::time::Duration::from_secs(interval)).await;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
today = chrono::Local::now().date_naive();
|
anchor = chrono::Local::now().date_naive();
|
||||||
}
|
}
|
||||||
for fid in ["52642258"] {
|
for (fid, path) in &favorites {
|
||||||
let res = process_favorite(&bili_client, fid, &connection).await;
|
let res = process_favorite(&bili_client, fid, path, &connection).await;
|
||||||
if let Err(e) = res {
|
if let Err(e) = res {
|
||||||
error!("Error: {e}");
|
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