Make list-tweets fetch all rather than last 200
This commit is contained in:
parent
25d3846e1c
commit
73ae1a8613
55
src/main.rs
55
src/main.rs
|
@ -9,6 +9,7 @@ use image::{DynamicImage, RgbaImage};
|
||||||
use tiny_skia::{Paint, PathBuilder, Pixmap, PixmapPaint, Stroke, Transform};
|
use tiny_skia::{Paint, PathBuilder, Pixmap, PixmapPaint, Stroke, Transform};
|
||||||
use twitter::*;
|
use twitter::*;
|
||||||
use wiki::*;
|
use wiki::*;
|
||||||
|
use std::borrow::Cow;
|
||||||
|
|
||||||
static APP_USER_AGENT: &str = concat!(
|
static APP_USER_AGENT: &str = concat!(
|
||||||
"bot_",
|
"bot_",
|
||||||
|
@ -143,25 +144,41 @@ fn do_list_tweets() -> StdError<()> {
|
||||||
)?
|
)?
|
||||||
.json::<serde_json::Value>()?;
|
.json::<serde_json::Value>()?;
|
||||||
|
|
||||||
let id = user["id"].as_u64().unwrap();
|
let id = user["id"].as_u64().unwrap().to_string();
|
||||||
|
let mut timeline = vec!();
|
||||||
let timeline: serde_json::Value = twitter_api(
|
let mut last_id: Option<u64> = None;
|
||||||
reqwest::Url::parse_with_params(
|
loop {
|
||||||
&TwitterEndpoint::UserTimeline.to_string(),
|
event!(Level::INFO, last_id, "Fetching chunk of tweets...");
|
||||||
[
|
let mut params: Vec<(&str, Cow<str>)> = vec!(
|
||||||
("count", "200"),
|
("count", "200".into()),
|
||||||
("exclude_replies", "true"),
|
("exclude_replies", "true".into()),
|
||||||
("include_retweets", "false"),
|
("include_rts", "false".into()),
|
||||||
("trim_user", "true"),
|
("trim_user", "true".into()),
|
||||||
("user_id", id.to_string().as_ref()),
|
("user_id", Cow::Borrowed(&id)),
|
||||||
],
|
);
|
||||||
)?,
|
if let Some(since_id) = last_id {
|
||||||
Some(&user_token),
|
// Get next chunk of tweets before those we've fetched
|
||||||
APIAction::Get,
|
params.push(("max_id", (since_id - 1).to_string().into()))
|
||||||
&[],
|
}
|
||||||
)?
|
let timeline_chunk = twitter_api(
|
||||||
.json()?;
|
reqwest::Url::parse_with_params(
|
||||||
for tweet in timeline.as_array().unwrap() {
|
&TwitterEndpoint::UserTimeline.to_string(),
|
||||||
|
params,
|
||||||
|
)?,
|
||||||
|
Some(&user_token),
|
||||||
|
APIAction::Get,
|
||||||
|
&[],
|
||||||
|
)?
|
||||||
|
.json::<serde_json::Value>()?;
|
||||||
|
let chunk = timeline_chunk.as_array().unwrap().to_owned();
|
||||||
|
event!(Level::INFO, count=chunk.len(), "Got tweets.");
|
||||||
|
if chunk.len() == 0 {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
last_id = Some(chunk.last().unwrap().as_object().unwrap()["id"].as_u64().unwrap());
|
||||||
|
timeline.extend(chunk);
|
||||||
|
}
|
||||||
|
for tweet in timeline {
|
||||||
let tweet = tweet.as_object().unwrap();
|
let tweet = tweet.as_object().unwrap();
|
||||||
println!("{}, \"{}\"", tweet["id"], tweet["text"]);
|
println!("{}, \"{}\"", tweet["id"], tweet["text"]);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue