mirror of
https://framagit.org/veretcle/scootaloo.git
synced 2025-07-20 17:11:19 +02:00
feat: add customizable page_size to twitter timeline
This commit is contained in:
14
src/lib.rs
14
src/lib.rs
@@ -28,6 +28,7 @@ use tokio::{spawn, sync::Mutex};
|
|||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
|
|
||||||
const DEFAULT_RATE_LIMIT: usize = 4;
|
const DEFAULT_RATE_LIMIT: usize = 4;
|
||||||
|
const DEFAULT_PAGE_SIZE: i32 = 200;
|
||||||
|
|
||||||
/// This is where the magic happens
|
/// This is where the magic happens
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
@@ -44,6 +45,11 @@ pub async fn run(config: Config) {
|
|||||||
|
|
||||||
let mut stream = futures::stream::iter(config.mastodon.into_values())
|
let mut stream = futures::stream::iter(config.mastodon.into_values())
|
||||||
.map(|mastodon_config| {
|
.map(|mastodon_config| {
|
||||||
|
// calculate Twitter page size
|
||||||
|
let page_size = mastodon_config
|
||||||
|
.twitter_page_size
|
||||||
|
.unwrap_or_else(|| config.twitter.page_size.unwrap_or(DEFAULT_PAGE_SIZE));
|
||||||
|
|
||||||
// create temporary value for each task
|
// create temporary value for each task
|
||||||
let scootaloo_cache_path = config.scootaloo.cache_path.clone();
|
let scootaloo_cache_path = config.scootaloo.cache_path.clone();
|
||||||
let token = get_oauth2_token(&config.twitter);
|
let token = get_oauth2_token(&config.twitter);
|
||||||
@@ -59,8 +65,12 @@ pub async fn run(config: Config) {
|
|||||||
drop(lconn);
|
drop(lconn);
|
||||||
|
|
||||||
// get user timeline feed (Vec<tweet>)
|
// get user timeline feed (Vec<tweet>)
|
||||||
let mut feed =
|
let mut feed = get_user_timeline(
|
||||||
get_user_timeline(&mastodon_config.twitter_screen_name, &token, last_tweet_id)
|
&mastodon_config.twitter_screen_name,
|
||||||
|
&token,
|
||||||
|
last_tweet_id,
|
||||||
|
page_size,
|
||||||
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
// empty feed -> exiting
|
// empty feed -> exiting
|
||||||
|
@@ -32,10 +32,11 @@ pub async fn get_user_timeline(
|
|||||||
screen_name: &str,
|
screen_name: &str,
|
||||||
token: &Token,
|
token: &Token,
|
||||||
lid: Option<u64>,
|
lid: Option<u64>,
|
||||||
|
page_size: i32,
|
||||||
) -> Result<Vec<Tweet>, Box<dyn Error>> {
|
) -> Result<Vec<Tweet>, Box<dyn Error>> {
|
||||||
// fix the page size to 200 as it is the maximum Twitter authorizes
|
// fix the page size to 200 as it is the maximum Twitter authorizes
|
||||||
let (_, feed) = user_timeline(UserID::from(screen_name.to_owned()), true, false, token)
|
let (_, feed) = user_timeline(UserID::from(screen_name.to_owned()), true, false, token)
|
||||||
.with_page_size(200)
|
.with_page_size(page_size)
|
||||||
.older(lid)
|
.older(lid)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user