First ever functionnal version

This commit is contained in:
VC
2020-03-01 14:51:39 +01:00
parent 18655f1e68
commit d6332a6252

View File

@@ -63,7 +63,7 @@ fn get_oauth2_token(config: &Config) -> Token {
/// Get twitter user timeline /// Get twitter user timeline
fn get_user_timeline(config: &Config, token: Token, lid: Option<u64>) -> Result<Vec<Tweet>, Box<dyn Error>> { 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 // 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) .with_page_size(200)
.older(lid))?; .older(lid))?;
@@ -172,30 +172,31 @@ pub fn run(config: Config) {
// get Mastodon instance // get Mastodon instance
let mastodon = get_mastodon_token(&config.mastodon); 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>) // 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) 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…"); println!("Nothing to retrieve since last time, exiting…");
return; return;
} }
for tweet in &feed { // order needs to be chronological
println!("ID: {}\ttext: {}\tentities: {:#?}\tmedia: {:#?}", tweet.id, tweet.text, tweet.entities, tweet.extended_entities); feed.reverse();
}
/* for tweet in &feed {
write_state(&config.twitter.last_tweet_path, feed[0].id).unwrap_or_else(|e| // 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!("Cant write the last tweet retrieved: {}", e) panic!("Cant write the last tweet retrieved: {}", e)
); );
*/ }
} }