From 1f98954d2e45e38b1702a7b14db295d72c973363 Mon Sep 17 00:00:00 2001 From: VC Date: Mon, 27 Jul 2020 21:02:10 +0200 Subject: [PATCH 1/8] Revert "Use futures instead of tokio (for just one call, sounds more appropriate)" This reverts commit 980932778455716f6e789cb31d773e6f0b45a43e --- Cargo.lock | 4 ++-- Cargo.toml | 4 ++-- src/lib.rs | 7 ++++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 469c4ad..0a528e0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1623,15 +1623,15 @@ dependencies = [ [[package]] name = "scootaloo" -version = "0.2.1" +version = "0.2.0" dependencies = [ "clap", "egg-mode", "elefren", - "futures 0.3.5", "htmlescape", "reqwest", "serde", + "tokio 0.2.13", "toml", ] diff --git a/Cargo.toml b/Cargo.toml index 5994631..e937f5e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "scootaloo" -version = "0.2.1" +version = "0.2.0" authors = ["VC "] edition = "2018" @@ -11,7 +11,7 @@ serde = { version = "1.0", features = ["derive"] } toml = "^0.5" clap = "^2.33" -futures = "^0.3" +tokio = "^0.2" egg-mode = "^0.14" elefren = "^0.20" diff --git a/src/lib.rs b/src/lib.rs index c262876..07ab08b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,8 +9,8 @@ use std::{ error::Error, }; -// futures -use futures::executor::block_on; +//tokio +use tokio::runtime::Runtime; // toml use serde::Deserialize; @@ -77,7 +77,8 @@ fn get_oauth2_token(config: &Config) -> Token { /// Get twitter user timeline fn get_user_timeline(config: &Config, token: Token, lid: Option) -> Result, Box> { // fix the page size to 200 as it is the maximum Twitter authorizes - let (_timeline, feed) = block_on(user_timeline(UserID::from(String::from(&config.twitter.username)), true, false, &token) + let mut rt = Runtime::new()?; + let (_timeline, feed) = rt.block_on(user_timeline(UserID::from(String::from(&config.twitter.username)), true, false, &token) .with_page_size(200) .older(lid))?; From 367377c090b6a652ba501b84ee2d15d767e20376 Mon Sep 17 00:00:00 2001 From: VC Date: Wed, 10 Mar 2021 20:59:42 +0100 Subject: [PATCH 2/8] Update various shits and give tokio compat 0.2 --- Cargo.lock | 746 +++++++++++++++++++++++++++++++++++++++++++++-------- Cargo.toml | 14 +- src/lib.rs | 8 +- 3 files changed, 650 insertions(+), 118 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0a528e0..ae8cfaa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -54,7 +54,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4ed64ae6d9ebfd9893193c4b2532b1292ec97bd8271c9d7d0fa90cd78a34cba" dependencies = [ "backtrace-sys", - "cfg-if", + "cfg-if 0.1.9", "libc", "rustc-demangle", ] @@ -94,6 +94,18 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b41b7ea54a0c9d92199de89e20e58d49f02f8e699814ef3fdf266f6f748d15c7" +[[package]] +name = "base64" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff" + +[[package]] +name = "base64" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" + [[package]] name = "bitflags" version = "1.2.1" @@ -109,7 +121,16 @@ dependencies = [ "block-padding", "byte-tools", "byteorder", - "generic-array", + "generic-array 0.12.3", +] + +[[package]] +name = "block-buffer" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" +dependencies = [ + "generic-array 0.14.4", ] [[package]] @@ -121,6 +142,12 @@ dependencies = [ "byte-tools", ] +[[package]] +name = "bumpalo" +version = "3.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63396b8a4b9de3f4fdfb320ab6080762242f66a8ef174c49d8e19b674db4cdbe" + [[package]] name = "byte-tools" version = "0.3.1" @@ -152,9 +179,15 @@ dependencies = [ [[package]] name = "bytes" -version = "0.5.4" +version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "130aac562c0dd69c56b3b1cc8ffd2e17be31d0b6c25b61c96b76231aa23e39e1" +checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38" + +[[package]] +name = "bytes" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b700ce4376041dcd0a327fd0097c41095743c4c8af8887265942faf1100bd040" [[package]] name = "c2-chacha" @@ -190,6 +223,12 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b486ce3ccf7ffd79fdeb678eac06a9e6c09fc88d33836340becb8fffe87c5e33" +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + [[package]] name = "chrono" version = "0.4.10" @@ -256,9 +295,9 @@ dependencies = [ [[package]] name = "core-foundation" -version = "0.6.4" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25b9e03f145fd4f2bf705e07b900cd41fc636598fe5dc452fd0db1441c3f496d" +checksum = "0a89e2ae426ea83155dccf10c0fa6b1463ef6d5fcb44cee0b224a408fa640a62" dependencies = [ "core-foundation-sys", "libc", @@ -266,9 +305,15 @@ dependencies = [ [[package]] name = "core-foundation-sys" -version = "0.6.2" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7ca8a5221364ef15ce201e8ed2f609fc312682a8f4e0e3d4aa5879764e0fa3b" +checksum = "ea221b5284a47e40033bf9b66f35f984ec0ea2931eb03505246cd27a963f981b" + +[[package]] +name = "cpuid-bool" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8aebca1129a03dc6dc2b127edd729435bbc4a37e1d5f4d7513165089ceb02634" [[package]] name = "crc32fast" @@ -276,7 +321,7 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ba125de2af0df55319f41944744ad91c71113bf74a4646efff39afe1f6842db1" dependencies = [ - "cfg-if", + "cfg-if 0.1.9", ] [[package]] @@ -297,7 +342,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "058ed274caafc1f60c4997b5fc07bf7dc7cca454af7c6e81edffe5f33f70dace" dependencies = [ "autocfg 1.0.0", - "cfg-if", + "cfg-if 0.1.9", "crossbeam-utils", "lazy_static", "maybe-uninit", @@ -311,7 +356,7 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c695eeca1e7173472a32221542ae469b3e9aac3a4fc81f7696bcad82029493db" dependencies = [ - "cfg-if", + "cfg-if 0.1.9", "crossbeam-utils", ] @@ -322,17 +367,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8" dependencies = [ "autocfg 1.0.0", - "cfg-if", + "cfg-if 0.1.9", "lazy_static", ] [[package]] name = "crypto-mac" -version = "0.7.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4434400df11d95d556bac068ddfedd482915eb18fe8bea89bc80b6e4b1c179e5" +checksum = "b584a330336237c1eecd3e94266efb216c56ed91225d634cb2991c5f3fd1aeab" dependencies = [ - "generic-array", + "generic-array 0.14.4", "subtle", ] @@ -359,7 +404,16 @@ version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5" dependencies = [ - "generic-array", + "generic-array 0.12.3", +] + +[[package]] +name = "digest" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +dependencies = [ + "generic-array 0.14.4", ] [[package]] @@ -376,11 +430,11 @@ checksum = "4358a9e11b9a09cf52383b451b49a169e8d797b68aa02301ff586d70d9661ea3" [[package]] name = "egg-mode" -version = "0.14.0" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb89a86be94dc0be1397975c57914998ad721d57903ec969de3ccec2a6b9dd41" +checksum = "5f877bc908325f50163ff1670a4733eabf87942511ccfd907fbef4e239c3f8aa" dependencies = [ - "base64 0.11.0", + "base64 0.12.3", "chrono", "derive_more", "futures 0.3.5", @@ -395,10 +449,10 @@ dependencies = [ "regex", "serde", "serde_json", - "sha-1", + "sha-1 0.9.4", "thiserror", - "tokio 0.2.13", - "url 2.1.1", + "tokio 0.2.25", + "url 2.2.1", ] [[package]] @@ -409,24 +463,25 @@ checksum = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3" [[package]] name = "elefren" -version = "0.20.1" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfca8d8d0147086081224e22183a37a7b98e3230b945a717f1b5a0eed5fb07af" +checksum = "ba08a959d3824df696d49c2ec023f45851f663c47b57b2de933aab749104cd18" dependencies = [ "chrono", "doc-comment", "hyper-old-types", "isolang", "log", - "reqwest", + "reqwest 0.9.24", "serde", "serde_derive", "serde_json", "serde_qs", - "serde_urlencoded", + "serde_urlencoded 0.6.1", "skeptic", "tap-reader", "try_from", + "tungstenite", "url 1.7.2", ] @@ -436,7 +491,7 @@ version = "0.8.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cd8d03faa7fe0c1431609dfad7bbe827af30f82e1e2ae6f7ee4fca6bd764bc28" dependencies = [ - "cfg-if", + "cfg-if 0.1.9", ] [[package]] @@ -483,7 +538,7 @@ version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6bd6d6f4752952feb71363cffc9ebac9411b75b87c6ab6058c40c8900cf43c0f" dependencies = [ - "cfg-if", + "cfg-if 0.1.9", "crc32fast", "libc", "miniz_oxide", @@ -510,6 +565,16 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" +[[package]] +name = "form_urlencoded" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191" +dependencies = [ + "matches", + "percent-encoding 2.1.0", +] + [[package]] name = "fuchsia-cprng" version = "0.1.1" @@ -636,7 +701,7 @@ dependencies = [ "futures-sink", "futures-task", "memchr", - "pin-project", + "pin-project 0.4.8", "pin-utils", "proc-macro-hack", "proc-macro-nested", @@ -652,13 +717,23 @@ dependencies = [ "typenum", ] +[[package]] +name = "generic-array" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817" +dependencies = [ + "typenum", + "version_check 0.9.1", +] + [[package]] name = "getrandom" version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb" dependencies = [ - "cfg-if", + "cfg-if 0.1.9", "libc", "wasi", ] @@ -693,7 +768,7 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9433d71e471c1736fd5a61b671fc0b148d7a2992f666c958d03cd8feb3b88d1" dependencies = [ - "bytes 0.5.4", + "bytes 0.5.6", "fnv", "futures-core", "futures-sink", @@ -702,10 +777,35 @@ dependencies = [ "indexmap", "log", "slab", - "tokio 0.2.13", - "tokio-util", + "tokio 0.2.25", + "tokio-util 0.2.0", ] +[[package]] +name = "h2" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d832b01df74254fe364568d6ddc294443f61cbec82816b60904303af87efae78" +dependencies = [ + "bytes 1.0.1", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http 0.2.0", + "indexmap", + "slab", + "tokio 1.3.0", + "tokio-util 0.6.4", + "tracing", +] + +[[package]] +name = "hashbrown" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04" + [[package]] name = "hermit-abi" version = "0.1.8" @@ -717,12 +817,12 @@ dependencies = [ [[package]] name = "hmac" -version = "0.7.1" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5dcb5e64cda4c23119ab41ba960d1e170a774c8e4b9d9e6a9bc18aabf5e59695" +checksum = "126888268dcc288495a26bf004b38c5fdbb31682f992c84ceb046a1f0fe38840" dependencies = [ "crypto-mac", - "digest", + "digest 0.9.0", ] [[package]] @@ -748,7 +848,7 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b708cc7f06493459026f53b9a61a7a121a5d1ec6238dee58ea4941132b30156b" dependencies = [ - "bytes 0.5.4", + "bytes 0.5.6", "fnv", "itoa", ] @@ -771,7 +871,17 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13d5ff830006f7646652e057693569bfe0d51760c0085a071769d142a205111b" dependencies = [ - "bytes 0.5.4", + "bytes 0.5.6", + "http 0.2.0", +] + +[[package]] +name = "http-body" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2861bd27ee074e5ee891e8b539837a9430012e249d7f0ca2d795650f579c1994" +dependencies = [ + "bytes 1.0.1", "http 0.2.0", ] @@ -781,6 +891,12 @@ version = "1.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cd179ae861f0c2e53da70d892f5f3029f9594be0c41dc5269cd371691b1dc2f9" +[[package]] +name = "httpdate" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "494b4d60369511e7dea41cf646832512a94e542f68bb9c49e54518e0f468eb47" + [[package]] name = "hyper" version = "0.12.35" @@ -817,7 +933,7 @@ version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fa1c527bbc634be72aa7ba31e4e4def9bbb020f5416916279b7c705cd838893e" dependencies = [ - "bytes 0.5.4", + "bytes 0.5.6", "futures-channel", "futures-core", "futures-util", @@ -828,13 +944,37 @@ dependencies = [ "itoa", "log", "net2", - "pin-project", + "pin-project 0.4.8", "time", - "tokio 0.2.13", + "tokio 0.2.25", "tower-service", "want 0.3.0", ] +[[package]] +name = "hyper" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8e946c2b1349055e0b72ae281b238baf1a3ea7307c7e9f9d64673bdd9c26ac7" +dependencies = [ + "bytes 1.0.1", + "futures-channel", + "futures-core", + "futures-util", + "h2 0.3.1", + "http 0.2.0", + "http-body 0.4.0", + "httparse", + "httpdate", + "itoa", + "pin-project 1.0.5", + "socket2", + "tokio 1.3.0", + "tower-service", + "tracing", + "want 0.3.0", +] + [[package]] name = "hyper-old-types" version = "0.11.0" @@ -871,13 +1011,26 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3adcd308402b9553630734e9c36b77a7e48b3821251ca2493e8cd596763aafaa" dependencies = [ - "bytes 0.5.4", + "bytes 0.5.6", "hyper 0.13.2", "native-tls", - "tokio 0.2.13", + "tokio 0.2.25", "tokio-tls", ] +[[package]] +name = "hyper-tls" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" +dependencies = [ + "bytes 1.0.1", + "hyper 0.14.4", + "native-tls", + "tokio 1.3.0", + "tokio-native-tls", +] + [[package]] name = "idna" version = "0.1.5" @@ -902,11 +1055,21 @@ dependencies = [ [[package]] name = "indexmap" -version = "1.3.2" +version = "1.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "076f042c5b7b98f31d205f1249267e12a6518c1481e9dae9764af19b707d2292" +checksum = "824845a0bf897a9042383849b02c1bc219c2383772efcd5c6f9766fa4b81aef3" dependencies = [ "autocfg 1.0.0", + "hashbrown", +] + +[[package]] +name = "input_buffer" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19a8a95243d5a0398cae618ec29477c6e3cb631152be5c19481f80bc71559754" +dependencies = [ + "bytes 0.5.6", ] [[package]] @@ -918,6 +1081,12 @@ dependencies = [ "libc", ] +[[package]] +name = "ipnet" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47be2f14c678be2fdcab04ab1171db51b2762ce6f0a8ee87c8dd4a04ed216135" + [[package]] name = "isolang" version = "1.0.0" @@ -935,6 +1104,15 @@ version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b8b7a7c0c47db5545ed3fef7468ee7bb5b74691498139e4b3f6a20685dc6dd8e" +[[package]] +name = "js-sys" +version = "0.3.48" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc9f84f9b115ce7843d60706df1422a916680bfdfcbdb0447c5614ff9d7e4d78" +dependencies = [ + "wasm-bindgen", +] + [[package]] name = "kernel32-sys" version = "0.2.2" @@ -959,9 +1137,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.70" +version = "0.2.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3baa92041a6fec78c687fa0cc2b3fae8884f743d672cf551bed1d6dac6988d0f" +checksum = "03b07a082330a35e43f63177cc01689da34fbffa0105e1246cf0311472cac73a" [[package]] name = "lock_api" @@ -978,7 +1156,7 @@ version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" dependencies = [ - "cfg-if", + "cfg-if 0.1.9", ] [[package]] @@ -1035,28 +1213,41 @@ dependencies = [ [[package]] name = "mio" -version = "0.6.21" +version = "0.6.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "302dec22bcf6bae6dfb69c647187f4b4d0fb6f535521f7bc022430ce8e12008f" +checksum = "4afd66f5b91bf2a3bc13fad0e21caedac168ca4c707504e75585648ae80e4cc4" dependencies = [ - "cfg-if", + "cfg-if 0.1.9", "fuchsia-zircon", "fuchsia-zircon-sys", "iovec", "kernel32-sys", "libc", "log", - "miow", + "miow 0.2.2", "net2", "slab", "winapi 0.2.8", ] [[package]] -name = "miow" -version = "0.2.1" +name = "mio" +version = "0.7.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919" +checksum = "a5dede4e2065b3842b8b0af444119f3aa331cc7cc2dd20388bfb0f5d5a38823a" +dependencies = [ + "libc", + "log", + "miow 0.3.6", + "ntapi", + "winapi 0.3.8", +] + +[[package]] +name = "miow" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebd808424166322d4a38da87083bfddd3ac4c131334ed55856112eb06d46944d" dependencies = [ "kernel32-sys", "net2", @@ -1065,10 +1256,20 @@ dependencies = [ ] [[package]] -name = "native-tls" -version = "0.2.3" +name = "miow" +version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b2df1a4c22fd44a62147fd8f13dd0f95c9d8ca7b2610299b2a2f9cf8964274e" +checksum = "5a33c1b55807fbed163481b5ba66db4b2fa6cde694a5027be10fb724206c5897" +dependencies = [ + "socket2", + "winapi 0.3.8", +] + +[[package]] +name = "native-tls" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8d96b2e1c8da3957d58100b09f102c6d9cfdfced01b7ec5a8974044bb09dbd4" dependencies = [ "lazy_static", "libc", @@ -1084,15 +1285,24 @@ dependencies = [ [[package]] name = "net2" -version = "0.2.33" +version = "0.2.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42550d9fb7b6684a6d404d9fa7250c2eb2646df731d1c06afc06dcee9e1bcf88" +checksum = "391630d12b68002ae1e25e8f974306474966550ad82dac6886fb8910c19568ae" dependencies = [ - "cfg-if", + "cfg-if 0.1.9", "libc", "winapi 0.3.8", ] +[[package]] +name = "ntapi" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a31937dea023539c72ddae0e3571deadc1414b300483fa7aaec176168cfa9d2" +dependencies = [ + "winapi 0.3.8", +] + [[package]] name = "num-integer" version = "0.1.42" @@ -1124,9 +1334,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.4.0" +version = "1.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b631f7e854af39a1739f401cf34a8a013dfe09eac4fa4dba91e9768bd28168d" +checksum = "af8b08b04175473088b46763e51ee54da5f9a164bc162f615b91bc179dbf15a3" [[package]] name = "opaque-debug" @@ -1135,13 +1345,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" [[package]] -name = "openssl" -version = "0.10.28" +name = "opaque-debug" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "973293749822d7dd6370d6da1e523b0d1db19f06c459134c658b2a4261378b52" +checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" + +[[package]] +name = "openssl" +version = "0.10.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "038d43985d1ddca7a9900630d8cd031b56e4794eecc2e9ea39dd17aa04399a70" dependencies = [ "bitflags", - "cfg-if", + "cfg-if 1.0.0", "foreign-types", "lazy_static", "libc", @@ -1156,9 +1372,9 @@ checksum = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" [[package]] name = "openssl-sys" -version = "0.9.54" +version = "0.9.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1024c0a59774200a555087a6da3f253a9095a5f344e353b212ac4c8b8e450986" +checksum = "921fc71883267538946025deffb622905ecad223c28efbfdef9bb59a0175f3e6" dependencies = [ "autocfg 1.0.0", "cc", @@ -1184,7 +1400,7 @@ version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b876b1b9e7ac6e1a74a6da34d25c42e17e8862aa409cbbbdcfc8d86c6f3bc62b" dependencies = [ - "cfg-if", + "cfg-if 0.1.9", "cloudabi", "libc", "redox_syscall", @@ -1249,7 +1465,16 @@ version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7804a463a8d9572f13453c516a5faea534a2403d7ced2f0c7e100eeff072772c" dependencies = [ - "pin-project-internal", + "pin-project-internal 0.4.8", +] + +[[package]] +name = "pin-project" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96fa8ebb90271c4477f144354485b8068bd8f6b78b428b01ba892ca26caf0b63" +dependencies = [ + "pin-project-internal 1.0.5", ] [[package]] @@ -1263,12 +1488,29 @@ dependencies = [ "syn", ] +[[package]] +name = "pin-project-internal" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "758669ae3558c6f74bd2a18b41f7ac0b5a195aea6639d6a9b5e5d1ad5ba24c0b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "pin-project-lite" version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "237844750cfbb86f67afe27eee600dfbbcb6188d734139b534cbfbf4f96792ae" +[[package]] +name = "pin-project-lite" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc0e1f259c92177c30a4c9d177246edd0a3568b25756a977d0632cf8fa37e905" + [[package]] name = "pin-utils" version = "0.1.0" @@ -1301,9 +1543,9 @@ checksum = "8e946095f9d3ed29ec38de908c22f95d9ac008e424c7bcae54c75a79c527c694" [[package]] name = "proc-macro2" -version = "1.0.9" +version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c09721c6781493a2a492a96b5a5bf19b65917fe6728884e7c44dd0c60ca3435" +checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71" dependencies = [ "unicode-xid", ] @@ -1318,7 +1560,7 @@ dependencies = [ "idna 0.2.0", "lazy_static", "regex", - "url 2.1.1", + "url 2.2.1", ] [[package]] @@ -1563,7 +1805,7 @@ dependencies = [ "native-tls", "serde", "serde_json", - "serde_urlencoded", + "serde_urlencoded 0.5.5", "time", "tokio 0.1.22", "tokio-executor", @@ -1572,7 +1814,41 @@ dependencies = [ "tokio-timer", "url 1.7.2", "uuid", - "winreg", + "winreg 0.6.2", +] + +[[package]] +name = "reqwest" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf12057f289428dbf5c591c74bf10392e4a8003f993405a902f20117019022d4" +dependencies = [ + "base64 0.13.0", + "bytes 1.0.1", + "encoding_rs", + "futures-core", + "futures-util", + "http 0.2.0", + "http-body 0.4.0", + "hyper 0.14.4", + "hyper-tls 0.5.0", + "ipnet", + "js-sys", + "lazy_static", + "log", + "mime", + "native-tls", + "percent-encoding 2.1.0", + "pin-project-lite 0.2.6", + "serde", + "serde_urlencoded 0.7.0", + "tokio 1.3.0", + "tokio-native-tls", + "url 2.2.1", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "winreg 0.7.0", ] [[package]] @@ -1623,15 +1899,16 @@ dependencies = [ [[package]] name = "scootaloo" -version = "0.2.0" +version = "0.2.1" dependencies = [ "clap", "egg-mode", "elefren", "htmlescape", - "reqwest", + "reqwest 0.11.2", "serde", - "tokio 0.2.13", + "tokio 1.3.0", + "tokio-compat-02", "toml", ] @@ -1643,10 +1920,11 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "security-framework" -version = "0.3.4" +version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ef2429d7cefe5fd28bd1d2ed41c944547d4ff84776f5935b456da44593a16df" +checksum = "d493c5f39e02dfb062cd8f33301f90f9b13b650e8c1b1d0fd75c19dd64bff69d" dependencies = [ + "bitflags", "core-foundation", "core-foundation-sys", "libc", @@ -1655,11 +1933,12 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "0.3.3" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e31493fc37615debb8c5090a7aeb4a9730bc61e77ab10b9af59f1a202284f895" +checksum = "dee48cdde5ed250b0d3252818f646e174ab414036edb884dde62d80a3ac6082d" dependencies = [ "core-foundation-sys", + "libc", ] [[package]] @@ -1733,16 +2012,53 @@ dependencies = [ "url 1.7.2", ] +[[package]] +name = "serde_urlencoded" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ec5d77e2d4c73717816afac02670d5c4f534ea95ed430442cad02e7a6e32c97" +dependencies = [ + "dtoa", + "itoa", + "serde", + "url 2.2.1", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edfa57a7f8d9c1d260a549e7224100f6c43d43f9103e06dd8b4095a9b2b43ce9" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + [[package]] name = "sha-1" version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7d94d0bede923b3cea61f3f1ff57ff8cdfd77b400fb8f9998949e0cf04163df" dependencies = [ - "block-buffer", - "digest", + "block-buffer 0.7.3", + "digest 0.8.1", "fake-simd", - "opaque-debug", + "opaque-debug 0.2.3", +] + +[[package]] +name = "sha-1" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfebf75d25bd900fd1e7d11501efab59bc846dbc76196839663e6637bba9f25f" +dependencies = [ + "block-buffer 0.9.0", + "cfg-if 1.0.0", + "cpuid-bool", + "digest 0.9.0", + "opaque-debug 0.3.0", ] [[package]] @@ -1788,6 +2104,17 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c2fb2ec9bcd216a5b0d0ccf31ab17b5ed1d627960edff65bbe95d3ce221cefc" +[[package]] +name = "socket2" +version = "0.3.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "122e570113d28d773067fab24266b66753f6ea915758651696b6e35e49f88d6e" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "winapi 0.3.8", +] + [[package]] name = "string" version = "0.2.1" @@ -1805,15 +2132,15 @@ checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" [[package]] name = "subtle" -version = "1.0.0" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d67a5a62ba6e01cb2192ff309324cb4875d0c451d55fe2319433abe7a05a8ee" +checksum = "1e81da0851ada1f3e9d4312c704aa4f8806f0f9d69faaf8df2f3464b4a9437c2" [[package]] name = "syn" -version = "1.0.16" +version = "1.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "123bd9499cfb380418d509322d7a6d52e5315f064fe4b3ad18a53d6b92c07859" +checksum = "8fd9bc7ccc2688b3344c2f48b9b546648b25ce0b20fc717ee7fa7981a8ca9717" dependencies = [ "proc-macro2", "quote", @@ -1854,7 +2181,7 @@ version = "3.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" dependencies = [ - "cfg-if", + "cfg-if 0.1.9", "libc", "rand 0.7.3", "redox_syscall", @@ -1919,7 +2246,7 @@ checksum = "5a09c0b5bb588872ab2f09afa13ee6e9dac11e10a0ec9e8e3ba39a5a5d530af6" dependencies = [ "bytes 0.4.12", "futures 0.1.29", - "mio", + "mio 0.6.23", "num_cpus", "tokio-current-thread", "tokio-executor", @@ -1932,21 +2259,37 @@ dependencies = [ [[package]] name = "tokio" -version = "0.2.13" +version = "0.2.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa5e81d6bc4e67fe889d5783bd2a128ab2e0cfa487e0be16b6a8d177b101616" +checksum = "6703a273949a90131b290be1fe7b039d0fc884aa1935860dfcbe056f28cd8092" dependencies = [ - "bytes 0.5.4", + "bytes 0.5.6", "fnv", "iovec", "lazy_static", "memchr", - "mio", - "pin-project-lite", + "mio 0.6.23", + "num_cpus", + "pin-project-lite 0.1.4", "slab", "tokio-macros", ] +[[package]] +name = "tokio" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d56477f6ed99e10225f38f9f75f872f29b8b8bd8c0b946f63345bb144e9eeda" +dependencies = [ + "autocfg 1.0.0", + "bytes 1.0.1", + "libc", + "memchr", + "mio 0.7.9", + "num_cpus", + "pin-project-lite 0.2.6", +] + [[package]] name = "tokio-buf" version = "0.1.1" @@ -1958,6 +2301,20 @@ dependencies = [ "futures 0.1.29", ] +[[package]] +name = "tokio-compat-02" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7d4237822b7be8fff0a7a27927462fad435dcb6650f95cea9e946bf6bdc7e07" +dependencies = [ + "bytes 0.5.6", + "once_cell", + "pin-project-lite 0.2.6", + "tokio 0.2.25", + "tokio 1.3.0", + "tokio-stream", +] + [[package]] name = "tokio-current-thread" version = "0.1.7" @@ -1991,15 +2348,25 @@ dependencies = [ [[package]] name = "tokio-macros" -version = "0.2.5" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0c3acc6aa564495a0f2e1d59fab677cd7f81a19994cfc7f3ad0e64301560389" +checksum = "e44da00bfc73a25f814cd8d7e57a68a5c31b74b3152a0a1d1f590c97ed06265a" dependencies = [ "proc-macro2", "quote", "syn", ] +[[package]] +name = "tokio-native-tls" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7d995660bd2b7f8c1568414c1126076c13fbb725c40112dc0120b78eb9b717b" +dependencies = [ + "native-tls", + "tokio 1.3.0", +] + [[package]] name = "tokio-reactor" version = "0.1.12" @@ -2010,7 +2377,7 @@ dependencies = [ "futures 0.1.29", "lazy_static", "log", - "mio", + "mio 0.6.23", "num_cpus", "parking_lot", "slab", @@ -2019,6 +2386,17 @@ dependencies = [ "tokio-sync", ] +[[package]] +name = "tokio-stream" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c535f53c0cfa1acace62995a8994fc9cc1f12d202420da96ff306ee24d576469" +dependencies = [ + "futures-core", + "pin-project-lite 0.2.6", + "tokio 1.3.0", +] + [[package]] name = "tokio-sync" version = "0.1.8" @@ -2038,7 +2416,7 @@ dependencies = [ "bytes 0.4.12", "futures 0.1.29", "iovec", - "mio", + "mio 0.6.23", "tokio-io", "tokio-reactor", ] @@ -2079,7 +2457,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7bde02a3a5291395f59b06ec6945a3077602fac2b07eeeaf0dee2122f3619828" dependencies = [ "native-tls", - "tokio 0.2.13", + "tokio 0.2.25", ] [[package]] @@ -2088,12 +2466,26 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "571da51182ec208780505a32528fc5512a8fe1443ab960b3f2f3ef093cd16930" dependencies = [ - "bytes 0.5.4", + "bytes 0.5.6", "futures-core", "futures-sink", "log", - "pin-project-lite", - "tokio 0.2.13", + "pin-project-lite 0.1.4", + "tokio 0.2.25", +] + +[[package]] +name = "tokio-util" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec31e5cc6b46e653cf57762f36f71d5e6386391d88a72fd6db4508f8f676fb29" +dependencies = [ + "bytes 1.0.1", + "futures-core", + "futures-sink", + "log", + "pin-project-lite 0.2.6", + "tokio 1.3.0", ] [[package]] @@ -2111,6 +2503,26 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e987b6bf443f4b5b3b6f38704195592cca41c5bb7aedd3c3693c7081f8289860" +[[package]] +name = "tracing" +version = "0.1.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01ebdc2bb4498ab1ab5f5b73c5803825e60199229ccba0698170e3be0e7f959f" +dependencies = [ + "cfg-if 1.0.0", + "pin-project-lite 0.2.6", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f50de3927f93d202783f4513cda820ab47ef17f624b03c096e86ef00c67e6b5f" +dependencies = [ + "lazy_static", +] + [[package]] name = "try-lock" version = "0.2.2" @@ -2123,14 +2535,34 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "283d3b89e1368717881a9d51dad843cc435380d8109c9e47d38780a324698d8b" dependencies = [ - "cfg-if", + "cfg-if 0.1.9", +] + +[[package]] +name = "tungstenite" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfea31758bf674f990918962e8e5f07071a3161bd7c4138ed23e416e1ac4264e" +dependencies = [ + "base64 0.11.0", + "byteorder", + "bytes 0.5.6", + "http 0.2.0", + "httparse", + "input_buffer", + "log", + "native-tls", + "rand 0.7.3", + "sha-1 0.8.2", + "url 2.2.1", + "utf-8", ] [[package]] name = "typenum" -version = "1.11.2" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d2783fe2d6b8c1101136184eb41be8b1ad379e4657050b8aaff0c79ee7575f9" +checksum = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33" [[package]] name = "unicase" @@ -2184,15 +2616,22 @@ dependencies = [ [[package]] name = "url" -version = "2.1.1" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "829d4a8476c35c9bf0bbce5a3b23f4106f79728039b726d292bb93bc106787cb" +checksum = "9ccd964113622c8e9322cfac19eb1004a07e636c545f325da085d5cdde6f1f8b" dependencies = [ + "form_urlencoded", "idna 0.2.0", "matches", "percent-encoding 2.1.0", ] +[[package]] +name = "utf-8" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05e42f7c18b8f902290b009cde6d651262f956c98bc51bca4cd1d511c9cd85c7" + [[package]] name = "uuid" version = "0.7.4" @@ -2264,6 +2703,84 @@ version = "0.9.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" +[[package]] +name = "wasm-bindgen" +version = "0.2.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ee1280240b7c461d6a0071313e08f34a60b0365f14260362e5a2b17d1d31aa7" +dependencies = [ + "cfg-if 1.0.0", + "serde", + "serde_json", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b7d8b6942b8bb3a9b0e73fc79b98095a27de6fa247615e59d096754a3bc2aa8" +dependencies = [ + "bumpalo", + "lazy_static", + "log", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e67a5806118af01f0d9045915676b22aaebecf4178ae7021bc171dab0b897ab" +dependencies = [ + "cfg-if 1.0.0", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5ac38da8ef716661f0f36c0d8320b89028efe10c7c0afde65baffb496ce0d3b" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc053ec74d454df287b9374ee8abb36ffd5acb95ba87da3ba5b7d3fe20eb401e" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d6f8ec44822dd71f5f221a5847fb34acd9060535c1211b70a05844c0f6383b1" + +[[package]] +name = "web-sys" +version = "0.3.48" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec600b26223b2948cedfde2a0aa6756dcf1fef616f43d7b3097aaf53a6c4d92b" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + [[package]] name = "winapi" version = "0.2.8" @@ -2316,6 +2833,15 @@ dependencies = [ "winapi 0.3.8", ] +[[package]] +name = "winreg" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0120db82e8a1e0b9fb3345a539c478767c0048d842860994d96113d5b667bd69" +dependencies = [ + "winapi 0.3.8", +] + [[package]] name = "ws2_32-sys" version = "0.2.1" diff --git a/Cargo.toml b/Cargo.toml index e937f5e..02efb79 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "scootaloo" -version = "0.2.0" +version = "0.2.1" authors = ["VC "] edition = "2018" @@ -8,14 +8,18 @@ edition = "2018" [dependencies] serde = { version = "1.0", features = ["derive"] } + toml = "^0.5" + clap = "^2.33" -tokio = "^0.2" -egg-mode = "^0.14" +tokio = { version = "1", features = ["rt-multi-thread"]} +tokio-compat-02 = "0.2" -elefren = "^0.20" +egg-mode = "^0.15" -reqwest = "^0.9" +elefren = "^0.22" + +reqwest = { version="^0.11", features = ["blocking"] } htmlescape = "^0.3" diff --git a/src/lib.rs b/src/lib.rs index 07ab08b..2033a13 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,6 +11,7 @@ use std::{ //tokio use tokio::runtime::Runtime; +use tokio_compat_02::FutureExt; // toml use serde::Deserialize; @@ -36,7 +37,7 @@ use elefren::{ }; // reqwest -use reqwest::Client; +use reqwest::blocking::Client; // htmlescape use htmlescape::decode_html; @@ -77,10 +78,11 @@ fn get_oauth2_token(config: &Config) -> Token { /// Get twitter user timeline fn get_user_timeline(config: &Config, token: Token, lid: Option) -> Result, Box> { // fix the page size to 200 as it is the maximum Twitter authorizes - let mut rt = Runtime::new()?; + let rt = Runtime::new()?; let (_timeline, feed) = rt.block_on(user_timeline(UserID::from(String::from(&config.twitter.username)), true, false, &token) .with_page_size(200) - .older(lid))?; + .older(lid) + .compat())?; Ok(feed.to_vec()) } From 2e052ebf6ac388c5857638226bb9cb99de1a1d9f Mon Sep 17 00:00:00 2001 From: VC Date: Sun, 18 Apr 2021 17:00:44 +0000 Subject: [PATCH 3/8] Still a WIP: need to use async reqwest to respect the global context of usage (reqwest::blocking is using async inside so it does not really sync whatever) --- .gitlab-ci.yml | 4 +- Cargo.lock | 339 ++++++++++++++++++++++++------------------------- Cargo.toml | 18 +-- README.md | 3 +- src/lib.rs | 182 ++++++++++++++++---------- src/main.rs | 25 ++++ 6 files changed, 316 insertions(+), 255 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 622893d..9cd248c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -6,5 +6,7 @@ rust-latest: image: rust:latest script: - cargo build --verbose - - cargo test --verbose + - cargo build --release --verbose + - strip target/release/${CI_PROJECT_NAME} + - du -h target/release/${CI_PROJECT_NAME} diff --git a/Cargo.lock b/Cargo.lock index ae8cfaa..56463dd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -94,12 +94,6 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b41b7ea54a0c9d92199de89e20e58d49f02f8e699814ef3fdf266f6f748d15c7" -[[package]] -name = "base64" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff" - [[package]] name = "base64" version = "0.13.0" @@ -265,6 +259,17 @@ dependencies = [ "bitflags", ] +[[package]] +name = "colored" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4ffc801dacf156c5854b9df4f425a626539c3a6ef7893cc0c5084a23f0b6c59" +dependencies = [ + "atty", + "lazy_static", + "winapi 0.3.8", +] + [[package]] name = "cookie" version = "0.12.0" @@ -373,9 +378,9 @@ dependencies = [ [[package]] name = "crypto-mac" -version = "0.8.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b584a330336237c1eecd3e94266efb216c56ed91225d634cb2991c5f3fd1aeab" +checksum = "4857fd85a0c34b3c3297875b747c1e02e06b6a0ea32dd892d8192b9ce0813ea6" dependencies = [ "generic-array 0.14.4", "subtle", @@ -431,27 +436,26 @@ checksum = "4358a9e11b9a09cf52383b451b49a169e8d797b68aa02301ff586d70d9661ea3" [[package]] name = "egg-mode" version = "0.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f877bc908325f50163ff1670a4733eabf87942511ccfd907fbef4e239c3f8aa" +source = "git+https://github.com/egg-mode-rs/egg-mode?rev=6b81073eba9c3b123ca0e80bdb5ef61d1758f131#6b81073eba9c3b123ca0e80bdb5ef61d1758f131" dependencies = [ - "base64 0.12.3", + "base64 0.13.0", "chrono", "derive_more", "futures 0.3.5", "hmac", - "hyper 0.13.2", - "hyper-tls 0.4.1", + "hyper 0.14.4", + "hyper-tls 0.5.0", "lazy_static", "mime", "native-tls", "percent-encoding 2.1.0", - "rand 0.7.3", + "rand 0.8.3", "regex", "serde", "serde_json", "sha-1 0.9.4", "thiserror", - "tokio 0.2.25", + "tokio 1.3.0", "url 2.2.1", ] @@ -735,7 +739,18 @@ checksum = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb" dependencies = [ "cfg-if 0.1.9", "libc", - "wasi", + "wasi 0.9.0+wasi-snapshot-preview1", +] + +[[package]] +name = "getrandom" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "wasi 0.10.2+wasi-snapshot-preview1", ] [[package]] @@ -762,25 +777,6 @@ dependencies = [ "tokio-io", ] -[[package]] -name = "h2" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9433d71e471c1736fd5a61b671fc0b148d7a2992f666c958d03cd8feb3b88d1" -dependencies = [ - "bytes 0.5.6", - "fnv", - "futures-core", - "futures-sink", - "futures-util", - "http 0.2.0", - "indexmap", - "log", - "slab", - "tokio 0.2.25", - "tokio-util 0.2.0", -] - [[package]] name = "h2" version = "0.3.1" @@ -796,7 +792,7 @@ dependencies = [ "indexmap", "slab", "tokio 1.3.0", - "tokio-util 0.6.4", + "tokio-util", "tracing", ] @@ -817,9 +813,9 @@ dependencies = [ [[package]] name = "hmac" -version = "0.8.1" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "126888268dcc288495a26bf004b38c5fdbb31682f992c84ceb046a1f0fe38840" +checksum = "c1441c6b1e930e2817404b5046f1f989899143a12bf92de603b69f4e0aee1e15" dependencies = [ "crypto-mac", "digest 0.9.0", @@ -865,16 +861,6 @@ dependencies = [ "tokio-buf", ] -[[package]] -name = "http-body" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13d5ff830006f7646652e057693569bfe0d51760c0085a071769d142a205111b" -dependencies = [ - "bytes 0.5.6", - "http 0.2.0", -] - [[package]] name = "http-body" version = "0.4.0" @@ -927,30 +913,6 @@ dependencies = [ "want 0.2.0", ] -[[package]] -name = "hyper" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa1c527bbc634be72aa7ba31e4e4def9bbb020f5416916279b7c705cd838893e" -dependencies = [ - "bytes 0.5.6", - "futures-channel", - "futures-core", - "futures-util", - "h2 0.2.1", - "http 0.2.0", - "http-body 0.3.1", - "httparse", - "itoa", - "log", - "net2", - "pin-project 0.4.8", - "time", - "tokio 0.2.25", - "tower-service", - "want 0.3.0", -] - [[package]] name = "hyper" version = "0.14.4" @@ -1005,19 +967,6 @@ dependencies = [ "tokio-io", ] -[[package]] -name = "hyper-tls" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3adcd308402b9553630734e9c36b77a7e48b3821251ca2493e8cd596763aafaa" -dependencies = [ - "bytes 0.5.6", - "hyper 0.13.2", - "native-tls", - "tokio 0.2.25", - "tokio-tls", -] - [[package]] name = "hyper-tls" version = "0.5.0" @@ -1072,6 +1021,15 @@ dependencies = [ "bytes 0.5.6", ] +[[package]] +name = "instant" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61124eeebbd69b8190558df225adf7e4caafce0d743919e5d6b19652314ec5ec" +dependencies = [ + "cfg-if 1.0.0", +] + [[package]] name = "iovec" version = "0.1.4" @@ -1150,6 +1108,15 @@ dependencies = [ "scopeguard", ] +[[package]] +name = "lock_api" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a3c91c24eae6777794bb1997ad98bbb87daf92890acab859f7eaa4320333176" +dependencies = [ + "scopeguard", +] + [[package]] name = "log" version = "0.4.8" @@ -1389,11 +1356,22 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f842b1982eb6c2fe34036a4fbfb06dd185a3f5c8edfaacdf7d1ea10b07de6252" dependencies = [ - "lock_api", - "parking_lot_core", + "lock_api 0.3.3", + "parking_lot_core 0.6.2", "rustc_version", ] +[[package]] +name = "parking_lot" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d7744ac029df22dca6284efe4e898991d28e3085c706c972bcd7da4a27a15eb" +dependencies = [ + "instant", + "lock_api 0.4.3", + "parking_lot_core 0.8.2", +] + [[package]] name = "parking_lot_core" version = "0.6.2" @@ -1409,6 +1387,20 @@ dependencies = [ "winapi 0.3.8", ] +[[package]] +name = "parking_lot_core" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ccb628cad4f84851442432c60ad8e1f607e29752d0bf072cbd0baf28aa34272" +dependencies = [ + "cfg-if 1.0.0", + "instant", + "libc", + "redox_syscall", + "smallvec 1.2.0", + "winapi 0.3.8", +] + [[package]] name = "percent-encoding" version = "1.0.1" @@ -1499,12 +1491,6 @@ dependencies = [ "syn", ] -[[package]] -name = "pin-project-lite" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "237844750cfbb86f67afe27eee600dfbbcb6188d734139b534cbfbf4f96792ae" - [[package]] name = "pin-project-lite" version = "0.2.6" @@ -1525,9 +1511,9 @@ checksum = "05da548ad6865900e60eaba7f589cc0783590a92e940c26953ff81ddbab2d677" [[package]] name = "ppv-lite86" -version = "0.2.6" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74490b50b9fbe561ac330df47c08f3f33073d2d00c150f719147d7c54522fa1b" +checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" [[package]] name = "proc-macro-hack" @@ -1619,13 +1605,25 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" dependencies = [ - "getrandom", + "getrandom 0.1.14", "libc", "rand_chacha 0.2.1", "rand_core 0.5.1", "rand_hc 0.2.0", ] +[[package]] +name = "rand" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e" +dependencies = [ + "libc", + "rand_chacha 0.3.0", + "rand_core 0.6.2", + "rand_hc 0.3.0", +] + [[package]] name = "rand_chacha" version = "0.1.1" @@ -1646,6 +1644,16 @@ dependencies = [ "rand_core 0.5.1", ] +[[package]] +name = "rand_chacha" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d" +dependencies = [ + "ppv-lite86", + "rand_core 0.6.2", +] + [[package]] name = "rand_core" version = "0.3.1" @@ -1667,7 +1675,16 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" dependencies = [ - "getrandom", + "getrandom 0.1.14", +] + +[[package]] +name = "rand_core" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7" +dependencies = [ + "getrandom 0.2.2", ] [[package]] @@ -1688,6 +1705,15 @@ dependencies = [ "rand_core 0.5.1", ] +[[package]] +name = "rand_hc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73" +dependencies = [ + "rand_core 0.6.2", +] + [[package]] name = "rand_isaac" version = "0.1.1" @@ -1839,7 +1865,7 @@ dependencies = [ "mime", "native-tls", "percent-encoding 2.1.0", - "pin-project-lite 0.2.6", + "pin-project-lite", "serde", "serde_urlencoded 0.7.0", "tokio 1.3.0", @@ -1899,16 +1925,17 @@ dependencies = [ [[package]] name = "scootaloo" -version = "0.2.1" +version = "0.3.2" dependencies = [ "clap", "egg-mode", "elefren", "htmlescape", + "log", "reqwest 0.11.2", "serde", + "simple_logger", "tokio 1.3.0", - "tokio-compat-02", "toml", ] @@ -2061,6 +2088,28 @@ dependencies = [ "opaque-debug 0.3.0", ] +[[package]] +name = "signal-hook-registry" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16f1d0fef1604ba8f7a073c7e701f213e056707210e9020af4528e0101ce11a6" +dependencies = [ + "libc", +] + +[[package]] +name = "simple_logger" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd57f17c093ead1d4a1499dc9acaafdd71240908d64775465543b8d9a9f1d198" +dependencies = [ + "atty", + "chrono", + "colored", + "log", + "winapi 0.3.8", +] + [[package]] name = "siphasher" version = "0.2.3" @@ -2257,24 +2306,6 @@ dependencies = [ "tokio-timer", ] -[[package]] -name = "tokio" -version = "0.2.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6703a273949a90131b290be1fe7b039d0fc884aa1935860dfcbe056f28cd8092" -dependencies = [ - "bytes 0.5.6", - "fnv", - "iovec", - "lazy_static", - "memchr", - "mio 0.6.23", - "num_cpus", - "pin-project-lite 0.1.4", - "slab", - "tokio-macros", -] - [[package]] name = "tokio" version = "1.3.0" @@ -2287,7 +2318,12 @@ dependencies = [ "memchr", "mio 0.7.9", "num_cpus", - "pin-project-lite 0.2.6", + "once_cell", + "parking_lot 0.11.1", + "pin-project-lite", + "signal-hook-registry", + "tokio-macros", + "winapi 0.3.8", ] [[package]] @@ -2301,20 +2337,6 @@ dependencies = [ "futures 0.1.29", ] -[[package]] -name = "tokio-compat-02" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7d4237822b7be8fff0a7a27927462fad435dcb6650f95cea9e946bf6bdc7e07" -dependencies = [ - "bytes 0.5.6", - "once_cell", - "pin-project-lite 0.2.6", - "tokio 0.2.25", - "tokio 1.3.0", - "tokio-stream", -] - [[package]] name = "tokio-current-thread" version = "0.1.7" @@ -2348,9 +2370,9 @@ dependencies = [ [[package]] name = "tokio-macros" -version = "0.2.6" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e44da00bfc73a25f814cd8d7e57a68a5c31b74b3152a0a1d1f590c97ed06265a" +checksum = "caf7b11a536f46a809a8a9f0bb4237020f70ecbf115b842360afb127ea2fda57" dependencies = [ "proc-macro2", "quote", @@ -2379,24 +2401,13 @@ dependencies = [ "log", "mio 0.6.23", "num_cpus", - "parking_lot", + "parking_lot 0.9.0", "slab", "tokio-executor", "tokio-io", "tokio-sync", ] -[[package]] -name = "tokio-stream" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c535f53c0cfa1acace62995a8994fc9cc1f12d202420da96ff306ee24d576469" -dependencies = [ - "futures-core", - "pin-project-lite 0.2.6", - "tokio 1.3.0", -] - [[package]] name = "tokio-sync" version = "0.1.8" @@ -2450,30 +2461,6 @@ dependencies = [ "tokio-executor", ] -[[package]] -name = "tokio-tls" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7bde02a3a5291395f59b06ec6945a3077602fac2b07eeeaf0dee2122f3619828" -dependencies = [ - "native-tls", - "tokio 0.2.25", -] - -[[package]] -name = "tokio-util" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "571da51182ec208780505a32528fc5512a8fe1443ab960b3f2f3ef093cd16930" -dependencies = [ - "bytes 0.5.6", - "futures-core", - "futures-sink", - "log", - "pin-project-lite 0.1.4", - "tokio 0.2.25", -] - [[package]] name = "tokio-util" version = "0.6.4" @@ -2484,7 +2471,7 @@ dependencies = [ "futures-core", "futures-sink", "log", - "pin-project-lite 0.2.6", + "pin-project-lite", "tokio 1.3.0", ] @@ -2510,7 +2497,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "01ebdc2bb4498ab1ab5f5b73c5803825e60199229ccba0698170e3be0e7f959f" dependencies = [ "cfg-if 1.0.0", - "pin-project-lite 0.2.6", + "pin-project-lite", "tracing-core", ] @@ -2703,6 +2690,12 @@ version = "0.9.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" +[[package]] +name = "wasi" +version = "0.10.2+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" + [[package]] name = "wasm-bindgen" version = "0.2.71" diff --git a/Cargo.toml b/Cargo.toml index 02efb79..21850ce 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "scootaloo" -version = "0.2.1" +version = "0.3.2" authors = ["VC "] edition = "2018" @@ -8,18 +8,12 @@ edition = "2018" [dependencies] serde = { version = "1.0", features = ["derive"] } - toml = "^0.5" - clap = "^2.33" - -tokio = { version = "1", features = ["rt-multi-thread"]} -tokio-compat-02 = "0.2" - -egg-mode = "^0.15" - +egg-mode = { git = "https://github.com/egg-mode-rs/egg-mode", rev = "6b81073eba9c3b123ca0e80bdb5ef61d1758f131" } elefren = "^0.22" - -reqwest = { version="^0.11", features = ["blocking"] } - +tokio = { version = "1", features = ["full"]} +reqwest = "^0.11" htmlescape = "^0.3" +log = "^0.4" +simple_logger = "^1.11" diff --git a/README.md b/README.md index 65c9986..ed5b972 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ A Twitter to Mastodon copy bot written in Rust It: * copies the content (text) of the original Tweet * dereferences the links -* gets every attach media (photo, video or gif) +* gets every attached media (photo, video or gif) If any of the last steps failed, the Toot gets published with the exact same text as the Tweet. @@ -74,4 +74,3 @@ echo -n '8189881949849' > last_tweet **This file should only contain the last tweet ID without any other char (no EOL or new line).** -Oh and everything is sync (and not async) so this does not run at a blazing speed… diff --git a/src/lib.rs b/src/lib.rs index 2033a13..c7fadbe 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,18 +1,14 @@ // std use std::{ - path::Path, borrow::Cow, collections::HashMap, - io::{stdin, copy}, + io::stdin, fmt, - fs::{read_to_string, write, create_dir_all, File, remove_file}, + fs::{read_to_string, write}, error::Error, + sync::{Arc, Mutex}, }; -//tokio -use tokio::runtime::Runtime; -use tokio_compat_02::FutureExt; - // toml use serde::Deserialize; @@ -37,34 +33,45 @@ use elefren::{ }; // reqwest -use reqwest::blocking::Client; +use reqwest::Url; + +// tokio +use tokio::{ + io::copy, + fs::{File, create_dir_all, remove_file}, + sync::mpsc, +}; // htmlescape use htmlescape::decode_html; +// log +use log::{info, warn, error, debug}; + /********** * Generic usage functions ***********/ /* * Those functions are related to the Twitter side of things */ -/// Read last tweet id from a file +/// Reads last tweet id from a file fn read_state(s: &str) -> Option { let state = read_to_string(s); if let Ok(s) = state { + debug!("Last Tweet ID (from file): {}", &s); return s.parse::().ok(); } None } -/// Write last treated tweet id to a file +/// Writes last treated tweet id to a file fn write_state(f: &str, s: u64) -> Result<(), std::io::Error> { write(f, format!("{}", s)) } -/// Get twitter oauth2 token +/// Gets Twitter oauth2 token fn get_oauth2_token(config: &Config) -> Token { let con_token = KeyPair::new(String::from(&config.twitter.consumer_key), String::from(&config.twitter.consumer_secret)); let access_token = KeyPair::new(String::from(&config.twitter.access_key), String::from(&config.twitter.access_secret)); @@ -75,19 +82,18 @@ fn get_oauth2_token(config: &Config) -> Token { } } -/// Get twitter user timeline -fn get_user_timeline(config: &Config, token: Token, lid: Option) -> Result, Box> { +/// Gets Twitter user timeline +async fn get_user_timeline(config: &Config, token: Token, lid: Option) -> Result, Box> { // fix the page size to 200 as it is the maximum Twitter authorizes - let rt = Runtime::new()?; - let (_timeline, feed) = rt.block_on(user_timeline(UserID::from(String::from(&config.twitter.username)), true, false, &token) + let (_, feed) = user_timeline(UserID::from(String::from(&config.twitter.username)), true, false, &token) .with_page_size(200) .older(lid) - .compat())?; + .await?; Ok(feed.to_vec()) } -/// decode urls from UrlEntities +/// Decodes urls from UrlEntities fn decode_urls(urls: &Vec) -> HashMap { let mut decoded_urls = HashMap::new(); @@ -101,6 +107,8 @@ fn decode_urls(urls: &Vec) -> HashMap { decoded_urls } +/// Decodes the Twitter mention to something that will make sense once Twitter has joined the +/// Fediverse fn twitter_mentions(ums: &Vec) -> HashMap { let mut decoded_mentions = HashMap::new(); @@ -111,18 +119,18 @@ fn twitter_mentions(ums: &Vec) -> HashMap { decoded_mentions } -/// Retrieve a single media from a tweet and store it in a temporary file -fn get_tweet_media(m: &MediaEntity, t: &str) -> Result> { +/// Retrieves a single media from a tweet and store it in a temporary file +async fn get_tweet_media(m: &MediaEntity, t: &str) -> Result> { match m.media_type { MediaType::Photo => { - return cache_media(&m.media_url_https, t); + return cache_media(&m.media_url_https, t).await; }, _ => { match &m.video_info { Some(v) => { for variant in &v.variants { if variant.content_type == "video/mp4" { - return cache_media(&variant.url, t); + return cache_media(&variant.url, t).await; } } return Err(Box::new(ScootalooError::new(format!("Media Type for {} is video but no mp4 file URL is available", &m.url).as_str()))); @@ -138,7 +146,7 @@ fn get_tweet_media(m: &MediaEntity, t: &str) -> Result> { /* * Those functions are related to the Mastodon side of things */ -/// Get Mastodon Data +/// Gets Mastodon Data fn get_mastodon_token(masto: &MastodonConfig) -> Mastodon { let data = Data { base: Cow::from(String::from(&masto.base)), @@ -151,7 +159,7 @@ fn get_mastodon_token(masto: &MastodonConfig) -> Mastodon { Mastodon::from(data) } -/// build toot text from tweet +/// Builds toot text from tweet fn build_basic_status(tweet: &Tweet) -> Result> { let mut toot = String::from(&tweet.text); @@ -177,35 +185,40 @@ fn build_basic_status(tweet: &Tweet) -> Result> { /* * Generic private functions */ -fn cache_media(u: &str, t: &str) -> Result> { + +/// Gets and caches Twitter Media inside the determined temp dir +async fn cache_media(u: &str, t: &str) -> Result> { // create dir - if !Path::new(t).is_dir() { - create_dir_all(t)?; - } + create_dir_all(t).await?; // get file - let client = Client::new(); - let mut response = client.get(u).send()?; + let mut response = reqwest::get(u).await?; // create local file - let dest_filename = match response.url() - .path_segments() - .and_then(|segments| segments.last()) { - Some(r) => r, - None => { - return Err(Box::new(ScootalooError::new(format!("Cannot determine the destination filename for {}", u).as_str()))); - }, - }; + let url = Url::parse(u)?; + let dest_filename = url.path_segments().ok_or_else(|| Box::new(ScootalooError::new(format!("Cannot determine the destination filename for {}", u).as_str())))? + .last().ok_or_else(|| Box::new(ScootalooError::new(format!("Cannot determine the destination filename for {}", u).as_str())))?; let dest_filepath = format!("{}/{}", t, dest_filename); - let mut dest_file = File::create(&dest_filepath)?; + let mut dest_file = File::create(&dest_filepath).await?; - copy(&mut response, &mut dest_file)?; + while let Some(chunk) = response.chunk().await? { + copy(&mut &*chunk, &mut dest_file).await?; + } Ok(dest_filepath) } +/********** + * This is the struct that holds the Mastodon Media ID and the Twitter Media URL at the same Time +**********/ +#[derive(Debug)] +struct ScootalooSpawnResponse { + mastodon_media_id: String, + twitter_media_url: String, +} + /********** * local error handler **********/ @@ -287,7 +300,7 @@ pub fn parse_toml(toml_file: &str) -> Config { /// Generic register function /// As this function is supposed to be run only once, it will panic for every error it encounters -/// Most of this function is a direct copy/paste of the official `mammut` crate +/// Most of this function is a direct copy/paste of the official `elefren` crate pub fn register(host: &str) { let mut builder = App::builder(); builder.client_name(Cow::from(String::from(env!("CARGO_PKG_NAME")))) @@ -315,7 +328,8 @@ pub fn register(host: &str) { } /// This is where the magic happens -pub fn run(config: Config) { +#[tokio::main] +pub async fn run(config: Config) { // retrieve the last tweet ID for the username let last_tweet_id = read_state(&config.scootaloo.last_tweet_path); @@ -323,16 +337,18 @@ pub fn run(config: Config) { let token = get_oauth2_token(&config); // get Mastodon instance - let mastodon = get_mastodon_token(&config.mastodon); + let mastodon = Arc::new(Mutex::new(get_mastodon_token(&config.mastodon))); // get user timeline feed (Vec) - let mut feed = get_user_timeline(&config, token, last_tweet_id).unwrap_or_else(|e| + let mut feed = get_user_timeline(&config, token, last_tweet_id) + .await + .unwrap_or_else(|e| panic!("Something went wrong when trying to retrieve {}’s timeline: {}", &config.twitter.username, e) ); // empty feed -> exiting if feed.is_empty() { - println!("Nothing to retrieve since last time, exiting…"); + info!("Nothing to retrieve since last time, exiting…"); return; } @@ -340,10 +356,12 @@ pub fn run(config: Config) { feed.reverse(); for tweet in &feed { + debug!("Treating Tweet {} inside feed", tweet.id); // determine if the tweet is part of a thread (response to self) or a standard response if let Some(r) = &tweet.in_reply_to_screen_name { if &r.to_lowercase() != &config.twitter.username.to_lowercase() { // we are responding not threading + info!("Tweet is a direct response, skipping"); continue; } }; @@ -352,7 +370,7 @@ pub fn run(config: Config) { let mut status_text = match build_basic_status(tweet) { Ok(t) => t, Err(e) => { - println!("Could not create status from tweet {}: {}", tweet.id ,e); + error!("Could not create status from tweet {}: {}", tweet.id ,e); continue; }, }; @@ -361,35 +379,64 @@ pub fn run(config: Config) { // reupload the attachments if any if let Some(m) = &tweet.extended_entities { + let (tx, mut rx) = mpsc::channel(4); + for media in &m.media { - let local_tweet_media_path = match get_tweet_media(&media, &config.scootaloo.cache_path) { - Ok(m) => m, - Err(e) => { - println!("Cannot get tweet media for {}: {}", &media.url, e); - continue; - }, - }; + // creating a new tx for this initial loop + let tx = tx.clone(); + // creating a new mastodon from the original mutex + let mastodon = mastodon.clone(); + // unfortunately for this to be thread safe, we need to clone a lot of structures + let media = media.clone(); + let cache_path = config.scootaloo.cache_path.clone(); - let mastodon_media_ids = match mastodon.media(Cow::from(String::from(&local_tweet_media_path))) { - Ok(m) => { - remove_file(&local_tweet_media_path).unwrap_or_else(|e| - println!("Attachment for {} has been upload, but I’m unable to remove the existing file: {}", &local_tweet_media_path, e) - ); - m.id - }, - Err(e) => { - println!("Cannot attach media {} to Mastodon Instance: {}", &local_tweet_media_path, e); - continue; + tokio::spawn(async move { + debug!("Spawing new async thread to treat {}", &media.id); + let local_tweet_media_path = match get_tweet_media(&media, &cache_path).await { + Ok(m) => m, + Err(e) => { + // we could have panicked here, no issue, but I’m not confortable using + // that for now + warn!("Cannot get tweet media for {}: {}", &media.url, e); + return; + } + }; + + // we cannot directly do all the stuff inside here because mastodon lock can + // live outside this + let mas_result = mastodon.lock().unwrap().media(Cow::from(String::from(&local_tweet_media_path))); + + match mas_result { + Ok(m) => { + remove_file(&local_tweet_media_path).await.unwrap_or_else(|e| + warn!("Attachment {} has been uploaded but I’m unable to remove the existing file: {}", &local_tweet_media_path, e) + ); + // we can unwrap here because we’re in a thread + tx.send(ScootalooSpawnResponse { + mastodon_media_id: m.id.clone(), + twitter_media_url: local_tweet_media_path.clone() + }).await.unwrap(); + }, + Err(e) => { + error!("Attachment {} cannot be uploaded to Mastodon Instance: {}", &local_tweet_media_path, e); + } } - }; + }); + } - status_medias.push(mastodon_media_ids); + // dropping the last tx otherwise recv() will wait indefinitely + drop(tx); - // last step, removing the reference to the media from with the toot’s text - status_text = status_text.replace(&media.url, ""); + while let Some(i) = rx.recv().await { + // pushes the media into the media vec + status_medias.push(i.mastodon_media_id); + // removes the URL from the original Tweet text + status_text = status_text.replace(&i.twitter_media_url, ""); } } + // finished reuploading attachments, now let’s do the toot baby! + debug!("Building corresponding Mastodon status"); let status = StatusBuilder::new() .status(&status_text) .media_ids(status_medias) @@ -397,7 +444,8 @@ pub fn run(config: Config) { .expect(format!("Cannot build status with text {}", &status_text).as_str()); // publish status - mastodon.new_status(status).unwrap(); + // again unwrap is safe here as we are in the main thread + mastodon.lock().unwrap().new_status(status).unwrap(); // this will panic if it cannot publish the status, which is a good thing, it allows the // last_tweet gathered not to be written diff --git a/src/main.rs b/src/main.rs index 575358a..529faa7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,6 +4,13 @@ use scootaloo::*; // clap use clap::{App, Arg, SubCommand}; +// log +use log::{LevelFilter, error}; +use simple_logger::SimpleLogger; + +// std +use std::str::FromStr; + fn main() { let matches = App::new(env!("CARGO_PKG_NAME")) .version(env!("CARGO_PKG_VERSION")) @@ -15,6 +22,13 @@ fn main() { .help("TOML config file for scootaloo (default /usr/local/etc/scootaloo.toml)") .takes_value(true) .display_order(1)) + .arg(Arg::with_name("log_level") + .short("l") + .long("loglevel") + .value_name("LOGLEVEL") + .help("Log level. Valid values are: Off, Warn, Error, Info, Debug") + .takes_value(true) + .display_order(2)) .subcommand(SubCommand::with_name("register") .version(env!("CARGO_PKG_VERSION")) .about("Command to register to a Mastodon Instance") @@ -32,7 +46,18 @@ fn main() { return; } + if matches.is_present("log_level") { + match LevelFilter::from_str(matches.value_of("log_level").unwrap()) { + Ok(level) => { SimpleLogger::new().with_level(level).init().unwrap()}, + Err(e) => { + SimpleLogger::new().with_level(LevelFilter::Error).init().unwrap(); + error!("Unknown log level filter: {}", e); + } + }; + } + let config = parse_toml(matches.value_of("config").unwrap_or("/usr/local/etc/scootaloo.toml")); run(config); } + From 09ed837a1b2e9d1079f5bfc47032e2748c682aec Mon Sep 17 00:00:00 2001 From: VC Date: Mon, 19 Apr 2021 21:19:47 +0200 Subject: [PATCH 4/8] =?UTF-8?q?Updating=20CHANGELOG=E2=80=AFto=20please=20?= =?UTF-8?q?@meduzen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index ddd1a49..2218899 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,19 @@ +# v0.3.2 + +* 100% async version +* now media are download in parallel thanks to async +* log are introduced into code for your viewing pleasure + +# v0.2.3 + +* using the async version of `reqwest` +* introducing async functions and make `tokio` the de facto executor for everything async + +# v0.2.1 + +* using `tokio-compat` to avoid having 3 different versions of `tokio` in the same executable +* encapsulating async calls inside blocking tokio runtime calls + # v0.1.8 * fix #1: mentions are treated like decoded urls (this is not really needed to push it this far but it would be easier in case you want to modify it) From c52fc52d23647992474ebc1950cb1327d27a6911 Mon Sep 17 00:00:00 2001 From: VC Date: Tue, 20 Apr 2021 11:38:50 +0200 Subject: [PATCH 5/8] Optimizing size of the final executable --- .gitlab-ci.yml | 5 ++--- Cargo.toml | 9 ++++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9cd248c..dec236c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -3,10 +3,9 @@ stages: rust-latest: stage: build + artifacts: + - target/release/scootaloo image: rust:latest script: - - cargo build --verbose - cargo build --release --verbose - - strip target/release/${CI_PROJECT_NAME} - - du -h target/release/${CI_PROJECT_NAME} diff --git a/Cargo.toml b/Cargo.toml index 21850ce..58954d4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "scootaloo" -version = "0.3.2" +version = "0.3.3" authors = ["VC "] edition = "2018" @@ -17,3 +17,10 @@ reqwest = "^0.11" htmlescape = "^0.3" log = "^0.4" simple_logger = "^1.11" + +[profile.release] +opt-level = 's' # Optimize for size. +lto = true # Link Time Optimization (LTO) +codegen-units = 1 # Set this to 1 to allow for maximum size reduction optimizations: +panic = 'abort' # removes the need for this extra unwinding code. + From 5b04bd27b90a806676c67a6c46dd5abc37de67d5 Mon Sep 17 00:00:00 2001 From: VC Date: Tue, 20 Apr 2021 11:39:43 +0200 Subject: [PATCH 6/8] Updating changelog --- CHANGELOG | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 2218899..a6d432b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,7 @@ +# v0.3.3 + +* optimizing the size of the final executable (now ⩽ 6MiB) + # v0.3.2 * 100% async version From 5a4dd5cb99515b37be18fd46dca286dc76132dad Mon Sep 17 00:00:00 2001 From: VC Date: Tue, 20 Apr 2021 11:40:49 +0200 Subject: [PATCH 7/8] paths --- .gitlab-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index dec236c..e77fcff 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,6 +4,7 @@ stages: rust-latest: stage: build artifacts: + paths: - target/release/scootaloo image: rust:latest script: From da808b0051f59026d050f1c9e115695e34d5447e Mon Sep 17 00:00:00 2001 From: VC Date: Tue, 20 Apr 2021 11:46:33 +0200 Subject: [PATCH 8/8] FUUUUUUUUUUUUUUU --- .gitlab-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e77fcff..3a2c988 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -9,4 +9,5 @@ rust-latest: image: rust:latest script: - cargo build --release --verbose + - strip target/release/${CI_PROJECT_NAME}