mirror of
https://framagit.org/veretcle/scootaloo.git
synced 2025-07-21 01:21:19 +02:00
First ever functionnal version
This commit is contained in:
35
src/lib.rs
35
src/lib.rs
@@ -63,7 +63,7 @@ fn get_oauth2_token(config: &Config) -> Token {
|
||||
/// Get twitter user timeline
|
||||
fn get_user_timeline(config: &Config, token: Token, lid: Option<u64>) -> Result<Vec<Tweet>, Box<dyn Error>> {
|
||||
// fix the page size to 200 as it is the maximum Twitter authorizes
|
||||
let (_timeline, feed) = block_on_all(user_timeline(&config.twitter.username, false, false, &token)
|
||||
let (_timeline, feed) = block_on_all(user_timeline(&config.twitter.username, true, false, &token)
|
||||
.with_page_size(200)
|
||||
.older(lid))?;
|
||||
|
||||
@@ -172,30 +172,31 @@ pub fn run(config: Config) {
|
||||
// get Mastodon instance
|
||||
let mastodon = get_mastodon_token(&config.mastodon);
|
||||
|
||||
let status = StatusBuilder::new("Hello World!".into());
|
||||
|
||||
mastodon.new_status(status).expect("tamerelol");
|
||||
|
||||
return;
|
||||
|
||||
// get user timeline feed (Vec<tweet>)
|
||||
let feed = get_user_timeline(&config, token, last_tweet_id).unwrap_or_else(|e|
|
||||
let mut feed = get_user_timeline(&config, token, last_tweet_id).unwrap_or_else(|e|
|
||||
panic!("Something went wrong when trying to retrieve {}’s timeline: {}", &config.twitter.username, e)
|
||||
);
|
||||
|
||||
if feed.len() == 0 {
|
||||
// empty feed -> exiting
|
||||
if feed.is_empty() {
|
||||
println!("Nothing to retrieve since last time, exiting…");
|
||||
return;
|
||||
}
|
||||
|
||||
for tweet in &feed {
|
||||
println!("ID: {}\ttext: {}\tentities: {:#?}\tmedia: {:#?}", tweet.id, tweet.text, tweet.entities, tweet.extended_entities);
|
||||
}
|
||||
// order needs to be chronological
|
||||
feed.reverse();
|
||||
|
||||
/*
|
||||
write_state(&config.twitter.last_tweet_path, feed[0].id).unwrap_or_else(|e|
|
||||
panic!("Can’t write the last tweet retrieved: {}", e)
|
||||
);
|
||||
*/
|
||||
for tweet in &feed {
|
||||
// build status based upon the original tweet
|
||||
let status = StatusBuilder::new(String::from(&tweet.text));
|
||||
|
||||
// publish status
|
||||
mastodon.new_status(status).unwrap();
|
||||
|
||||
// write the current state (tweet ID) to avoid copying it another time
|
||||
write_state(&config.twitter.last_tweet_path, tweet.id).unwrap_or_else(|e|
|
||||
panic!("Can’t write the last tweet retrieved: {}", e)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user