Merge branch 'count-argument' into 'main'

Add --post-count option

See merge request kernald/reddit-magnet!15
This commit is contained in:
Marc Plano-Lesay 2025-05-02 03:08:24 +00:00
commit cc91695765
3 changed files with 20 additions and 3 deletions

View file

@ -12,6 +12,10 @@ pub struct Args {
#[arg(short, long)]
pub db: Option<String>,
/// Number of posts to load per user
#[arg(long, default_value = "25")]
pub post_count: u32,
#[command(flatten)]
pub verbose: Verbosity<InfoLevel>,
}

View file

@ -82,7 +82,9 @@ async fn main() -> Result<()> {
let reddit_client = RedditClient::new();
let mut user_posts = MultiMap::new();
for username in unique_usernames {
let submissions = reddit_client.fetch_user_submissions(&username).await?;
let submissions = reddit_client
.fetch_user_submissions(&username, args.post_count)
.await?;
user_posts.insert_many(username, submissions);
}

View file

@ -1,5 +1,6 @@
use chrono::{DateTime, TimeZone, Utc};
use color_eyre::eyre::{Result, WrapErr};
use roux::util::FeedOption;
use roux::User;
use serde::{Deserialize, Serialize};
@ -21,10 +22,20 @@ impl RedditClient {
}
/// Fetch submissions for a user
pub async fn fetch_user_submissions(&self, username: &str) -> Result<Vec<RedditPost>> {
///
/// # Arguments
///
/// * `username` - The Reddit username to fetch submissions for
/// * `post_count` - The maximum number of posts to fetch
pub async fn fetch_user_submissions(
&self,
username: &str,
post_count: u32,
) -> Result<Vec<RedditPost>> {
let user = User::new(username);
let feed_option = FeedOption::new().limit(post_count);
let submissions = user
.submitted(None)
.submitted(Some(feed_option))
.await
.context(format!("Failed to fetch submissions for user {}", username))?;