From 49eef28056aa03ec12801d42002eda29107194aa Mon Sep 17 00:00:00 2001 From: Sam Willcocks Date: Tue, 13 Sep 2022 19:14:04 +0100 Subject: [PATCH] Format and fix clippy warnings --- src/main.rs | 36 +++++++++++++++++++----------------- src/wiki.rs | 2 +- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/main.rs b/src/main.rs index 5b34112..9492b18 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,10 +6,10 @@ mod twitter; mod wiki; use clap::{Parser, Subcommand}; use image::{DynamicImage, RgbaImage}; +use std::borrow::Cow; use tiny_skia::{Paint, PathBuilder, Pixmap, PixmapPaint, Stroke, Transform}; use twitter::*; use wiki::*; -use std::borrow::Cow; static APP_USER_AGENT: &str = concat!( "bot_", @@ -145,37 +145,38 @@ fn do_list_tweets() -> StdError<()> { .json::()?; let id = user["id"].as_u64().unwrap().to_string(); - let mut timeline = vec!(); + let mut timeline = vec![]; let mut last_id: Option = None; - loop { + loop { event!(Level::INFO, last_id, "Fetching chunk of tweets..."); - let mut params: Vec<(&str, Cow)> = vec!( + let mut params: Vec<(&str, Cow)> = vec![ ("count", "200".into()), ("exclude_replies", "true".into()), ("include_rts", "false".into()), ("trim_user", "true".into()), ("user_id", Cow::Borrowed(&id)), - ); + ]; if let Some(since_id) = last_id { // Get next chunk of tweets before those we've fetched params.push(("max_id", (since_id - 1).to_string().into())) } let timeline_chunk = twitter_api( - reqwest::Url::parse_with_params( - &TwitterEndpoint::UserTimeline.to_string(), - params, - )?, + reqwest::Url::parse_with_params(&TwitterEndpoint::UserTimeline.to_string(), params)?, Some(&user_token), APIAction::Get, &[], )? .json::()?; let chunk = timeline_chunk.as_array().unwrap().to_owned(); - event!(Level::INFO, count=chunk.len(), "Got tweets."); - if chunk.len() == 0 { + event!(Level::INFO, count = chunk.len(), "Got tweets."); + if chunk.is_empty() { break; } - last_id = Some(chunk.last().unwrap().as_object().unwrap()["id"].as_u64().unwrap()); + last_id = Some( + chunk.last().unwrap().as_object().unwrap()["id"] + .as_u64() + .unwrap(), + ); timeline.extend(chunk); } for tweet in timeline { @@ -216,16 +217,17 @@ fn get_client(headers: Option) -> StdError) -> StdError<()> { let all = scrape_web()?; let (title, filename) = if let Some(target) = target { - all.iter().find(|(title, _)| title.to_lowercase().contains(&target.to_lowercase())) + all.iter() + .find(|(title, _)| title.to_lowercase().contains(&target.to_lowercase())) } else { - all - .choose(&mut rand::thread_rng()) - }.ok_or("got no images m8")?; + all.choose(&mut rand::thread_rng()) + } + .ok_or("got no images m8")?; event!(Level::INFO, title, filename, "Picked random thing"); let client = get_client(None)?; event!(Level::INFO, "Fetching metadata..."); // TODO: could crash, probably doesn't matter - let meta = get_file_metadata(vec![filename])?.remove(0); + let meta = get_file_metadata(&[filename.as_str()])?.remove(0); event!(Level::INFO, %meta, "Got metadata"); event!(Level::INFO, url = meta.url.to_string(), "Fetching image"); let svg = client.get(meta.url).send()?.bytes()?; diff --git a/src/wiki.rs b/src/wiki.rs index 6fff280..46c6603 100644 --- a/src/wiki.rs +++ b/src/wiki.rs @@ -156,7 +156,7 @@ struct ExtMetaItem { value: T, } -pub fn get_file_metadata(files: Vec<&str>) -> StdError> { +pub fn get_file_metadata(files: &[&str]) -> StdError> { let client = get_client(None)?; // Api only lets us do 50 files in one request Ok(files