From 52f98690a566bb1529fccbac21fca8de01460d76 Mon Sep 17 00:00:00 2001 From: VC Date: Sat, 29 Feb 2020 15:39:27 +0100 Subject: [PATCH] Second series of tests --- Cargo.lock | 60 ++++++++++++++++++++++++++++++------------- Cargo.toml | 2 ++ src/lib.rs | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 119 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3472fb3..b292471 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -128,6 +128,12 @@ dependencies = [ "iovec", ] +[[package]] +name = "bytes" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "130aac562c0dd69c56b3b1cc8ffd2e17be31d0b6c25b61c96b76231aa23e39e1" + [[package]] name = "c2-chacha" version = "0.2.3" @@ -337,7 +343,7 @@ dependencies = [ "serde_derive", "serde_json", "sha-1", - "tokio", + "tokio 0.1.22", "url 1.7.2", ] @@ -491,7 +497,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a5b34c246847f938a410a03c5458c7fee2274436675e76d8b903c08efc29c462" dependencies = [ "byteorder", - "bytes", + "bytes 0.4.12", "fnv", "futures", "http", @@ -527,7 +533,7 @@ version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6ccf5ede3a895d8856620237b2f02972c1bbc78d2965ad7fe8838d4a0ed41f0" dependencies = [ - "bytes", + "bytes 0.4.12", "fnv", "itoa", ] @@ -538,7 +544,7 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6741c859c1b2463a423a1dbce98d418e6c3c3fc720fb0d45528657320920292d" dependencies = [ - "bytes", + "bytes 0.4.12", "futures", "http", "tokio-buf", @@ -556,7 +562,7 @@ version = "0.12.35" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9dbe6ed1438e1f8ad955a4701e9a944938e9519f6888d12d8558b645e247d5f6" dependencies = [ - "bytes", + "bytes 0.4.12", "futures", "futures-cpupool", "h2", @@ -569,7 +575,7 @@ dependencies = [ "net2", "rustc_version", "time", - "tokio", + "tokio 0.1.22", "tokio-buf", "tokio-executor", "tokio-io", @@ -586,7 +592,7 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3a800d6aa50af4b5850b2b0f659625ce9504df908e9733b635720483be26174f" dependencies = [ - "bytes", + "bytes 0.4.12", "futures", "hyper", "native-tls", @@ -600,7 +606,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ad5125567a8328ced412a29a52a3ca0a2520c617d40a8bee62d12d877eec236c" dependencies = [ "base64", - "bytes", + "bytes 0.4.12", "cfg-if", "http", "httparse", @@ -950,6 +956,12 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" +[[package]] +name = "pin-project-lite" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "237844750cfbb86f67afe27eee600dfbbcb6188d734139b534cbfbf4f96792ae" + [[package]] name = "pkg-config" version = "0.3.17" @@ -1189,7 +1201,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f88643aea3c1343c804950d7bf983bd2067f5ab59db6d613a08e05572f2714ab" dependencies = [ "base64", - "bytes", + "bytes 0.4.12", "cookie", "cookie_store", "encoding_rs", @@ -1206,7 +1218,7 @@ dependencies = [ "serde_json", "serde_urlencoded", "time", - "tokio", + "tokio 0.1.22", "tokio-executor", "tokio-io", "tokio-threadpool", @@ -1254,6 +1266,8 @@ dependencies = [ "clap", "egg-mode", "mammut", + "serde", + "tokio 0.2.13", "toml", ] @@ -1381,7 +1395,7 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d24114bfcceb867ca7f71a0d3fe45d45619ec47a6fbfa98cb14e14250bfa5d6d" dependencies = [ - "bytes", + "bytes 0.4.12", ] [[package]] @@ -1468,7 +1482,7 @@ version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a09c0b5bb588872ab2f09afa13ee6e9dac11e10a0ec9e8e3ba39a5a5d530af6" dependencies = [ - "bytes", + "bytes 0.4.12", "futures", "mio", "num_cpus", @@ -1486,13 +1500,23 @@ dependencies = [ "tokio-uds", ] +[[package]] +name = "tokio" +version = "0.2.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa5e81d6bc4e67fe889d5783bd2a128ab2e0cfa487e0be16b6a8d177b101616" +dependencies = [ + "bytes 0.5.4", + "pin-project-lite", +] + [[package]] name = "tokio-buf" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8fb220f46c53859a4b7ec083e41dec9778ff0b1851c0942b211edb89e0ccdc46" dependencies = [ - "bytes", + "bytes 0.4.12", "either", "futures", ] @@ -1503,7 +1527,7 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "25b2998660ba0e70d18684de5d06b70b70a3a747469af9dea7618cc59e75976b" dependencies = [ - "bytes", + "bytes 0.4.12", "futures", "tokio-io", ] @@ -1545,7 +1569,7 @@ version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57fc868aae093479e3131e3d165c93b1c7474109d13c90ec0dda2a1bbfff0674" dependencies = [ - "bytes", + "bytes 0.4.12", "futures", "log", ] @@ -1585,7 +1609,7 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "98df18ed66e3b72e742f185882a9e201892407957e45fbff8da17ae7a7c51f72" dependencies = [ - "bytes", + "bytes 0.4.12", "futures", "iovec", "mio", @@ -1628,7 +1652,7 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2a0b10e610b39c38b031a2fcab08e4b82f16ece36504988dcbd81dbba650d82" dependencies = [ - "bytes", + "bytes 0.4.12", "futures", "log", "mio", @@ -1643,7 +1667,7 @@ version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5076db410d6fdc6523df7595447629099a1fdc47b3d9f896220780fa48faf798" dependencies = [ - "bytes", + "bytes 0.4.12", "futures", "iovec", "libc", diff --git a/Cargo.toml b/Cargo.toml index 0a46c5f..144f7d1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,9 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +serde = { version = "1.0", features = ["derive"] } toml = "^0.5" clap = "^2.33" +tokio = "^0.2" egg-mode = "^0.13" mammut = "^0.13" diff --git a/src/lib.rs b/src/lib.rs index 2abf4c2..6114b7a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,79 @@ +// 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(); +}