feat: support mikan rss links
This commit is contained in:
@@ -1,20 +1,62 @@
|
||||
#![allow(unused_imports)]
|
||||
use eyre::Context;
|
||||
use loco_rs::{cli::playground, prelude::*};
|
||||
use itertools::Itertools;
|
||||
use loco_rs::{
|
||||
app::Hooks,
|
||||
boot::{BootResult, StartMode},
|
||||
environment::Environment,
|
||||
prelude::*,
|
||||
};
|
||||
use recorder::{
|
||||
app::App,
|
||||
extract::mikan::parse_mikan_rss_items_from_rss_link,
|
||||
migrations::Migrator,
|
||||
models::{
|
||||
subscribers::ROOT_SUBSCRIBER,
|
||||
subscriptions::{self, SubscriptionCreateFromRssDto},
|
||||
},
|
||||
};
|
||||
use sea_orm_migration::MigratorTrait;
|
||||
|
||||
async fn fetch_and_parse_rss_demo() -> eyre::Result<()> {
|
||||
let url =
|
||||
"https://mikanani.me/RSS/MyBangumi?token=FE9tccsML2nBPUUqpCuJW2uJZydAXCntHJ7RpD9LDP8%3d";
|
||||
async fn pull_mikan_bangumi_rss(ctx: &AppContext) -> eyre::Result<()> {
|
||||
let rss_link = "https://mikanani.me/RSS/Bangumi?bangumiId=3416&subgroupid=370";
|
||||
let subscription = if let Some(subscription) = subscriptions::Entity::find()
|
||||
.filter(subscriptions::Column::SourceUrl.eq(String::from(rss_link)))
|
||||
.one(&ctx.db)
|
||||
.await?
|
||||
{
|
||||
subscription
|
||||
} else {
|
||||
subscriptions::Model::add_subscription(
|
||||
ctx,
|
||||
subscriptions::SubscriptionCreateDto::Mikan(SubscriptionCreateFromRssDto {
|
||||
rss_link: rss_link.to_string(),
|
||||
display_name: String::from("Mikan Project - 我的番组"),
|
||||
enabled: Some(true),
|
||||
}),
|
||||
1,
|
||||
)
|
||||
.await?
|
||||
};
|
||||
|
||||
subscription.pull_subscription(ctx).await?;
|
||||
|
||||
let res = reqwest::get(url).await?.bytes().await?;
|
||||
let channel = rss::Channel::read_from(&res[..])?;
|
||||
println!("channel: {:#?}", channel);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn init() -> eyre::Result<AppContext> {
|
||||
let ctx = loco_rs::cli::playground::<App>().await?;
|
||||
let BootResult {
|
||||
app_context: ctx, ..
|
||||
} = loco_rs::boot::run_app::<App>(&StartMode::ServerOnly, ctx).await?;
|
||||
Migrator::up(&ctx.db, None).await?;
|
||||
Ok(ctx)
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> eyre::Result<()> {
|
||||
fetch_and_parse_rss_demo().await?;
|
||||
let ctx = init().await?;
|
||||
pull_mikan_bangumi_rss(&ctx).await?;
|
||||
|
||||
// let active_model: articles::ActiveModel = ActiveModel {
|
||||
// title: Set(Some("how to build apps in 3 steps".to_string())),
|
||||
@@ -25,7 +67,6 @@ async fn main() -> eyre::Result<()> {
|
||||
|
||||
// let res = articles::Entity::find().all(&ctx.db).await.unwrap();
|
||||
// println!("{:?}", res);
|
||||
println!("welcome to playground. edit me at `examples/playground.rs`");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user