Add --post-count option
This commit is contained in:
parent
bdcc0def42
commit
a91e243ecc
3 changed files with 20 additions and 3 deletions
|
|
@ -12,6 +12,10 @@ pub struct Args {
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
pub db: Option<String>,
|
pub db: Option<String>,
|
||||||
|
|
||||||
|
/// Number of posts to load per user
|
||||||
|
#[arg(long, default_value = "25")]
|
||||||
|
pub post_count: u32,
|
||||||
|
|
||||||
#[command(flatten)]
|
#[command(flatten)]
|
||||||
pub verbose: Verbosity<InfoLevel>,
|
pub verbose: Verbosity<InfoLevel>,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,9 @@ async fn main() -> Result<()> {
|
||||||
let reddit_client = RedditClient::new();
|
let reddit_client = RedditClient::new();
|
||||||
let mut user_posts = MultiMap::new();
|
let mut user_posts = MultiMap::new();
|
||||||
for username in unique_usernames {
|
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);
|
user_posts.insert_many(username, submissions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
use chrono::{DateTime, TimeZone, Utc};
|
use chrono::{DateTime, TimeZone, Utc};
|
||||||
use color_eyre::eyre::{Result, WrapErr};
|
use color_eyre::eyre::{Result, WrapErr};
|
||||||
|
use roux::util::FeedOption;
|
||||||
use roux::User;
|
use roux::User;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
|
@ -21,10 +22,20 @@ impl RedditClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fetch submissions for a user
|
/// 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 user = User::new(username);
|
||||||
|
let feed_option = FeedOption::new().limit(post_count);
|
||||||
let submissions = user
|
let submissions = user
|
||||||
.submitted(None)
|
.submitted(Some(feed_option))
|
||||||
.await
|
.await
|
||||||
.context(format!("Failed to fetch submissions for user {}", username))?;
|
.context(format!("Failed to fetch submissions for user {}", username))?;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue