mirror of
https://github.com/OMGeeky/twba.twitch_fetcher.git
synced 2026-02-23 15:49:57 +01:00
some fixes and logging
This commit is contained in:
3
Cargo.lock
generated
3
Cargo.lock
generated
@@ -3372,7 +3372,6 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "twba-twitch-data"
|
name = "twba-twitch-data"
|
||||||
version = "0.3.0"
|
version = "0.3.0"
|
||||||
source = "git+https://github.com/OMGeeky/twitch_data.git#908cbae28ff0c7b13e00a942955776c1c0e14707"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"async-recursion",
|
"async-recursion",
|
||||||
@@ -3396,7 +3395,7 @@ dependencies = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "twitch-fetcher"
|
name = "twba-twitch-fetcher"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "twitch-fetcher"
|
name = "twba-twitch-fetcher"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
|
|||||||
@@ -56,16 +56,16 @@ impl<'a> FetcherClient<'a> {
|
|||||||
.await
|
.await
|
||||||
.map_err(FetcherError::GetVideosError)?;
|
.map_err(FetcherError::GetVideosError)?;
|
||||||
for video in videos {
|
for video in videos {
|
||||||
info!("Adding video: {} to the database", video.title);
|
|
||||||
let existing_video_found = Videos::find()
|
let existing_video_found = Videos::find()
|
||||||
.filter(VideosColumn::TwitchId.eq(video.id.to_string()))
|
.filter(VideosColumn::TwitchId.eq(video.id.to_string()))
|
||||||
.one(&self.db)
|
.one(&self.db)
|
||||||
.await
|
.await?
|
||||||
.is_ok();
|
.is_some();
|
||||||
if existing_video_found {
|
if existing_video_found {
|
||||||
info!("Video with id: {} already exists in the database", video.id);
|
info!("Video with id: {} already exists in the database", video.id);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
info!("Adding video: {} to the database", video.title);
|
||||||
|
|
||||||
ActiveModel {
|
ActiveModel {
|
||||||
id: ActiveValue::NotSet,
|
id: ActiveValue::NotSet,
|
||||||
@@ -74,7 +74,7 @@ impl<'a> FetcherClient<'a> {
|
|||||||
user_id: ActiveValue::Set(user.id),
|
user_id: ActiveValue::Set(user.id),
|
||||||
created_at: ActiveValue::Set(video.created_at.to_rfc3339()),
|
created_at: ActiveValue::Set(video.created_at.to_rfc3339()),
|
||||||
youtube_id: ActiveValue::NotSet,
|
youtube_id: ActiveValue::NotSet,
|
||||||
youtube_playlist_name: ActiveValue::NotSet,
|
youtube_playlist_name: ActiveValue::Set("".to_string()),
|
||||||
youtube_preview_image_url: ActiveValue::NotSet,
|
youtube_preview_image_url: ActiveValue::NotSet,
|
||||||
youtube_playlist_id: ActiveValue::NotSet,
|
youtube_playlist_id: ActiveValue::NotSet,
|
||||||
duration: ActiveValue::Set(video.duration as i32),
|
duration: ActiveValue::Set(video.duration as i32),
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ async fn main() -> Result<()> {
|
|||||||
tracing_subscriber::fmt()
|
tracing_subscriber::fmt()
|
||||||
.with_max_level(tracing::Level::INFO)
|
.with_max_level(tracing::Level::INFO)
|
||||||
.with_env_filter(
|
.with_env_filter(
|
||||||
"sea_orm=warn,sea_orm_migration=warn,sqlx=warn,twba_fetcher=trace,twba_local_db=warn,twba_twitch_data=info,twba_downloader_config=info,twba_backup_config=info,other=warn",
|
"sea_orm=warn,sea_orm_migration=warn,sqlx=warn,twba_twitch_fetcher=trace,twba_local_db=warn,twba_twitch_data=info,twba_downloader_config=info,twba_backup_config=info,other=warn",
|
||||||
)
|
)
|
||||||
.init();
|
.init();
|
||||||
info!("Hello, world!");
|
info!("Hello, world!");
|
||||||
@@ -29,13 +29,18 @@ async fn run() -> Result<()> {
|
|||||||
.load()
|
.load()
|
||||||
.map_err(|e| FetcherError::LoadConfig(e.into()))?;
|
.map_err(|e| FetcherError::LoadConfig(e.into()))?;
|
||||||
|
|
||||||
|
trace!("Opening database");
|
||||||
let db = twba_local_db::open_database(Some(&conf.db_url)).await?;
|
let db = twba_local_db::open_database(Some(&conf.db_url)).await?;
|
||||||
twba_local_db::migrate_db(&db).await?;
|
twba_local_db::migrate_db(&db).await?;
|
||||||
|
trace!("Creating twitch client");
|
||||||
let twitch_client = twba_twitch_data::get_client()
|
let twitch_client = twba_twitch_data::get_client()
|
||||||
.await
|
.await
|
||||||
.map_err(FetcherError::CreateClientError)?;
|
.map_err(FetcherError::CreateClientError)?;
|
||||||
|
|
||||||
|
info!("Creating client");
|
||||||
let client = client::FetcherClient::new(conf, db, twitch_client);
|
let client = client::FetcherClient::new(conf, db, twitch_client);
|
||||||
|
info!("Fetching new videos");
|
||||||
client.fetch_new_videos().await?;
|
client.fetch_new_videos().await?;
|
||||||
|
info!("Done fetching new videos");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
use twba_backup_config::Conf;
|
|
||||||
|
|
||||||
pub use crate::errors::FetcherError;
|
pub use crate::errors::FetcherError;
|
||||||
pub(crate) use std::result::Result as StdResult;
|
pub(crate) use std::result::Result as StdResult;
|
||||||
pub(crate) use tracing::{debug, error, info, trace, warn};
|
pub(crate) use tracing::{debug, error, info, trace, warn};
|
||||||
|
|||||||
Reference in New Issue
Block a user