diff --git a/.github/workflows/dpz-bot.yml b/.github/workflows/bot.yml similarity index 70% rename from .github/workflows/dpz-bot.yml rename to .github/workflows/bot.yml index 670eec3..9af7633 100644 --- a/.github/workflows/dpz-bot.yml +++ b/.github/workflows/bot.yml @@ -1,4 +1,4 @@ -name: "DPZ Bot" +name: "The Bots" on: # run it on every 7 minutes @@ -27,9 +27,18 @@ jobs: key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}-${{ hashFiles('**/rust-toolchain.toml') }} - run: cargo build - - run: cargo run + - name: "Run for DPZ" + run: cargo run env: RSS_URL: https://dailyportalz.jp/feed/headline BSKY_ID: ${{ secrets.BSKY_DBZ_BOT_ID }} BSKY_PASSWORD: ${{ secrets.BSKY_DPZ_BOT_PASSWORD }} - MAX_BSKY_POSTS: 1 + MAX_BSKY_POSTS: 10 + + - name: "Run for Gihyo.jp" + run: cargo run + env: + RSS_URL: https://gihyo.jp/feed/rss2 + BSKY_ID: ${{ secrets.BSKY_GIHYO_BOT_ID }} + BSKY_PASSWORD: ${{ secrets.BSKY_GIHYO_BOT_PASSWORD }} + MAX_BSKY_POSTS: 10 diff --git a/README.md b/README.md index 9bea08e..462d184 100644 --- a/README.md +++ b/README.md @@ -8,9 +8,16 @@ Bluesky (https://bsky.app) 用のRSS botです。 * Site: https://dailyportalz.jp/ * RSS: https://dailyportalz.jp/feed/headline -* workflow: https://github.com/gfx/bluesky-rss-bot/blob/main/.github/workflows/dpz-bot.yml +* workflow: https://github.com/gfx/bluesky-rss-bot/blob/main/.github/workflows/bot.yml * Bluesky: https://bsky.app/profile/dpz-unofficial-bot.bsky.social +## Gihyo.jp + +* Site: https://gihyo.jp/ +* RSS: https://gihyo.jp/feed/rss2 +* workflow: https://github.com/gfx/bluesky-rss-bot/blob/main/.github/workflows/bot.yml +* Bluesky: https://bsky.app/profile/gihyo-unofficial.bsky.social + ## License MIT License. See [LICENSE](./LICENSE) for details. diff --git a/src/main.rs b/src/main.rs index 9d72280..8b8e834 100644 --- a/src/main.rs +++ b/src/main.rs @@ -40,7 +40,7 @@ async fn get_bsky_posts Result, Box> { let mut new_entries = vec![]; + let mut num_entries = 100; + for entry in feed.entries { let mut found = false; for post in &posts { @@ -77,6 +79,11 @@ async fn find_new_entries( break; } else { new_entries.push(entry); + + num_entries -= 1; + if num_entries <= 0 { + break; + } } } @@ -153,6 +160,11 @@ async fn post_entry( .link(&*url) .build(); + let created_at = entry + .published + .unwrap_or_else(|| chrono::Local::now().into()) + .to_rfc3339(); + println!("Posting entry {:?} {:?}", text, embed); let result = agent @@ -167,7 +179,7 @@ async fn post_entry( text, embed, facets: Some(facets), - created_at: chrono::Local::now().to_rfc3339(), + created_at, entities: None, labels: None, langs: None, @@ -195,11 +207,11 @@ async fn post_entries Result<(), Box> { let mut count = 0; for entry in entries.into_iter().rev() { + count += 1; if count > max_bsky_posts { break; } post_entry(agent, session, entry).await?; - count += 1; } Ok(())