Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a bot for gihyo.jp #2

Merged
merged 2 commits into from
Dec 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions .github/workflows/dpz-bot.yml → .github/workflows/bot.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "DPZ Bot"
name: "The Bots"

on:
# run it on every 7 minutes
Expand Down Expand Up @@ -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
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
18 changes: 15 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async fn get_bsky_posts<S: SessionStore + Send + Sync, T: XrpcClient + Send + Sy
actor: session.handle.clone(),
filter: Some("posts_no_replies".into()),
cursor: None,
limit: Some(10),
limit: Some(100),
})
.await?
.feed;
Expand All @@ -56,6 +56,8 @@ async fn find_new_entries(
) -> Result<Vec<Entry>, Box<dyn std::error::Error>> {
let mut new_entries = vec![];

let mut num_entries = 100;

for entry in feed.entries {
let mut found = false;
for post in &posts {
Expand All @@ -77,6 +79,11 @@ async fn find_new_entries(
break;
} else {
new_entries.push(entry);

num_entries -= 1;
if num_entries <= 0 {
break;
}
}
}

Expand Down Expand Up @@ -153,6 +160,11 @@ async fn post_entry<S: SessionStore + Send + Sync, T: XrpcClient + Send + Sync>(
.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
Expand All @@ -167,7 +179,7 @@ async fn post_entry<S: SessionStore + Send + Sync, T: XrpcClient + Send + Sync>(
text,
embed,
facets: Some(facets),
created_at: chrono::Local::now().to_rfc3339(),
created_at,
entities: None,
labels: None,
langs: None,
Expand Down Expand Up @@ -195,11 +207,11 @@ async fn post_entries<S: SessionStore + Send + Sync, T: XrpcClient + Send + Sync
) -> Result<(), Box<dyn std::error::Error>> {
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(())
Expand Down