// std use std::fs::read_to_string; // clap use clap::{App, Arg}; // toml use serde::Deserialize; // egg-mode use egg_mode::{ Token, KeyPair, tweet::{ user_timeline, Tweet, }, }; // tokio use tokio::runtime::current_thread::block_on_all; #[derive(Debug, Deserialize)] pub struct Config { twitter: TwitterConfig, } #[derive(Debug, Deserialize)] struct TwitterConfig { username: String, consumer_key: String, consumer_secret: String, access_key: String, access_secret: String, } impl Config { pub fn new() -> Config { let matches = App::new(env!("CARGO_PKG_NAME")) .version(env!("CARGO_PKG_VERSION")) .about("A Twitter to Mastodon bot") .arg(Arg::with_name("config") .short("c") .long("config") .value_name("CONFIG_FILE") .help("TOML config file for scootaloo (default /usr/local/etc/scootaloo.toml)") .takes_value(true) .display_order(1)) .get_matches(); let toml_file = matches.value_of("config").unwrap_or("/usr/local/etc/scootaloo.toml"); let toml_config = read_to_string(toml_file).unwrap_or_else(|e| panic!("Cannot open config file {}: {}", toml_file, e) ); let config: Config = toml::from_str(&toml_config).unwrap_or_else(|e| panic!("Cannot parse TOML file {}: {}", toml_file, e) ); config } } pub fn run(config: Config) { let con_token = KeyPair::new(config.twitter.consumer_key, config.twitter.consumer_secret); let access_token = KeyPair::new(config.twitter.access_key, config.twitter.access_secret); let token = Token::Access { consumer: con_token, access: access_token, }; let timeline = user_timeline(&config.twitter.username, false, false, &token) .with_page_size(200) .older(None); timeline.types(); }