Index: Cargo.lock ================================================================== --- Cargo.lock +++ Cargo.lock @@ -208,10 +208,11 @@ "chrono", "derive_builder 0.10.2", "diligent-date-parser", "never", "quick-xml 0.22.0", + "serde 1.0.130", ] [[package]] name = "atomic-waker" version = "1.0.0" @@ -355,10 +356,11 @@ checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" dependencies = [ "libc", "num-integer", "num-traits 0.2.14", + "serde 1.0.130", "time", "winapi 0.3.9", ] [[package]] @@ -1066,11 +1068,11 @@ "bytes 0.5.6", "fnv", "futures-core", "futures-sink", "futures-util", - "http 0.2.4", + "http 0.2.5", "indexmap", "slab", "tokio 0.2.25", "tokio-util", "tracing", @@ -1140,13 +1142,13 @@ "itoa", ] [[package]] name = "http" -version = "0.2.4" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "527e8c9ac747e28542699a951517aa9a6945af506cd1f2e1b53a576c17b6cc11" +checksum = "1323096b05d41827dadeaee54c9981958c0f94e670bc94ed80037d1a7b8b186b" dependencies = [ "bytes 1.1.0", "fnv", "itoa", ] @@ -1168,11 +1170,11 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13d5ff830006f7646652e057693569bfe0d51760c0085a071769d142a205111b" dependencies = [ "bytes 0.5.6", - "http 0.2.4", + "http 0.2.5", ] [[package]] name = "httparse" version = "1.5.1" @@ -1224,11 +1226,11 @@ "bytes 0.5.6", "futures-channel", "futures-core", "futures-util", "h2 0.2.7", - "http 0.2.4", + "http 0.2.5", "http-body 0.3.1", "httparse", "httpdate", "itoa", "pin-project", @@ -1303,13 +1305,13 @@ "hashbrown", ] [[package]] name = "instant" -version = "0.1.10" +version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bee0328b1209d157ef001c94dd85b4f8f64139adb0eac2659f4b08382b2f474d" +checksum = "716d3d89f35ac6a34fd0eed635395f4c3b76fa889338a4632e5231a8684216bd" dependencies = [ "cfg-if 1.0.0", ] [[package]] @@ -1319,10 +1321,16 @@ checksum = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" dependencies = [ "libc", ] +[[package]] +name = "ipnet" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68f2d64f2edebec4ce84ad108148e67e1064789bee435edc5b60ad398714a3a9" + [[package]] name = "itertools" version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "69ddb889f9d0d08a67338271fa9b62996bc788c7796a5c18cf057420aaed5eaf" @@ -1383,13 +1391,13 @@ "static_assertions", ] [[package]] name = "libc" -version = "0.2.102" +version = "0.2.103" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2a5ac8f984bfcf3a823267e5fde638acc3325f6496633a5da6bb6eb2171e103" +checksum = "dd8f7255a17a627354f321ef0055d63b898c6fb27eff628af4d1b66b7331edf6" [[package]] name = "linked-hash-map" version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1703,13 +1711,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "28988d872ab76095a6e6ac88d99b54fd267702734fd7ffe610ca27f533ddb95a" [[package]] name = "openssl-sys" -version = "0.9.66" +version = "0.9.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1996d2d305e561b70d1ee0c53f1542833f4e1ac6ce9a6708b6ff2738ca67dc82" +checksum = "69df2d8dfc6ce3aaf44b40dec6f487d5a886516cf6879c49e98e0710f310a058" dependencies = [ "autocfg 1.0.1", "cc", "libc", "pkg-config", @@ -1776,11 +1784,11 @@ dependencies = [ "cfg-if 1.0.0", "instant", "libc", "redox_syscall 0.2.10", - "smallvec 1.6.1", + "smallvec 1.7.0", "winapi 0.3.9", ] [[package]] name = "percent-encoding" @@ -1871,13 +1879,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkg-config" -version = "0.3.19" +version = "0.3.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c" +checksum = "7c9b1041b4387893b91ee6746cddfc28516aff326a3519fb2adf820932c5e6cb" [[package]] name = "polling" version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2182,20 +2190,55 @@ "mime 0.3.16", "mime_guess 2.0.3", "native-tls", "serde 1.0.130", "serde_json", - "serde_urlencoded", + "serde_urlencoded 0.5.5", "time", "tokio 0.1.22", "tokio-executor", "tokio-io", "tokio-threadpool", "tokio-timer", "url 1.7.2", "uuid", - "winreg", + "winreg 0.6.2", +] + +[[package]] +name = "reqwest" +version = "0.10.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0718f81a8e14c4dbb3b34cf23dc6aaf9ab8a0dfec160c534b3dbca1aaa21f47c" +dependencies = [ + "base64 0.13.0", + "bytes 0.5.6", + "encoding_rs", + "futures-core", + "futures-util", + "http 0.2.5", + "http-body 0.3.1", + "hyper 0.13.10", + "hyper-tls 0.4.3", + "ipnet", + "js-sys", + "lazy_static", + "log 0.4.14", + "mime 0.3.16", + "mime_guess 2.0.3", + "native-tls", + "percent-encoding 2.1.0", + "pin-project-lite 0.2.7", + "serde 1.0.130", + "serde_urlencoded 0.7.0", + "tokio 0.2.25", + "tokio-tls", + "url 2.2.2", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "winreg 0.7.0", ] [[package]] name = "rss" version = "1.9.0" @@ -2202,25 +2245,26 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "99979205510c60f80a119dedbabd0b8426517384edf205322f8bcd51796bcef9" dependencies = [ "derive_builder 0.9.0", "quick-xml 0.17.2", - "reqwest", + "reqwest 0.9.24", ] [[package]] name = "rsstg" -version = "0.1.17" +version = "0.1.19" dependencies = [ "anyhow", "atom_syndication", "chrono", "config", - "futures 0.3.17", + "futures 0.1.31", "futures-util", "lazy_static", "regex", + "reqwest 0.10.10", "rss", "sqlx", "telegram-bot", "tokio 0.2.25", ] @@ -2374,10 +2418,22 @@ "dtoa", "itoa", "serde 1.0.130", "url 1.7.2", ] + +[[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 1.0.130", +] [[package]] name = "sha-1" version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2443,13 +2499,13 @@ "maybe-uninit", ] [[package]] name = "smallvec" -version = "1.6.1" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e" +checksum = "1ecab6c735a6bb4139c0caafd0cc3635748bbb3acf4550e8138122099251f309" [[package]] name = "socket2" version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2528,11 +2584,11 @@ "rand 0.8.4", "serde 1.0.130", "serde_json", "sha-1", "sha2", - "smallvec 1.6.1", + "smallvec 1.7.0", "sqlformat", "sqlx-rt", "stringprep", "thiserror", "url 2.2.2", @@ -2613,13 +2669,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" [[package]] name = "syn" -version = "1.0.76" +version = "1.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6f107db402c2c2055242dbf4d2af0e69197202e9faacbef9571bbe47f5a1b84" +checksum = "5239bc68e0fef57495900cfea4e8dc75596d9a319d7e16b1e0a440d24e6fe0a0" dependencies = [ "proc-macro2", "quote", "unicode-xid", ] @@ -2710,13 +2766,13 @@ "winapi 0.3.9", ] [[package]] name = "tinyvec" -version = "1.4.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5241dd6f21443a3606b432718b166d3cedc962fd4b8bea54a8bc7f514ebda986" +checksum = "f83b2a3d4d9091d0abd7eba4dc2710b1718583bd4d8992e2190720ea38f391f7" dependencies = [ "tinyvec_macros", ] [[package]] @@ -3139,10 +3195,12 @@ version = "0.2.78" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "632f73e236b219150ea279196e54e610f5dbafa5d61786303d4da54f84e47fce" dependencies = [ "cfg-if 1.0.0", + "serde 1.0.130", + "serde_json", "wasm-bindgen-macro", ] [[package]] name = "wasm-bindgen-backend" @@ -3219,13 +3277,13 @@ "cc", ] [[package]] name = "whoami" -version = "1.1.3" +version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7741161a40200a867c96dfa5574544efa4178cf4c8f770b62dd1cc0362d7ae1" +checksum = "483a59fee1a93fec90eb08bc2eb4315ef10f4ebc478b3a5fadc969819cb66117" dependencies = [ "wasm-bindgen", "web-sys", ] @@ -3269,10 +3327,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b2986deb581c4fe11b621998a5e53361efe6b48a151178d0cd9eeffa4dc6acc9" dependencies = [ "winapi 0.3.9", ] + +[[package]] +name = "winreg" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0120db82e8a1e0b9fb3345a539c478767c0048d842860994d96113d5b667bd69" +dependencies = [ + "winapi 0.3.9", +] [[package]] name = "ws2_32-sys" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" Index: Cargo.toml ================================================================== --- Cargo.toml +++ Cargo.toml @@ -1,22 +1,26 @@ [package] name = "rsstg" -version = "0.1.18" +version = "0.1.19" authors = ["arcade"] edition = "2018" [dependencies] -atom_syndication = "*" +atom_syndication = { version = "*", features = [ "with-serde" ] } chrono = "*" config = "*" futures = "*" futures-util = "*" regex = "*" +#reqwest = { version = "*", features = [ "brotli", "gzip", "deflate" ]} +reqwest = "~0.10" rss = { version = "*", features = [ "from_url" ] } sqlx = { version = "*", features = [ "postgres", "tls", "runtime-async-std-native-tls", "chrono" ] } +#surf = "*" telegram-bot = "*" -tokio = { version = "0.2", features = ["macros" ] } +tokio = { version = "~0.2", features = [ "macros" ] } #, "rt-multi-thread", "time" ] } +#tokio-stream = "*" lazy_static = "*" anyhow = "*" Index: src/main.rs ================================================================== --- src/main.rs +++ src/main.rs @@ -2,12 +2,14 @@ use std::sync::{Arc, Mutex}; use config; use tokio; +use reqwest; use rss; +use atom_syndication; use chrono::DateTime; use regex::Regex; @@ -14,11 +16,10 @@ use telegram_bot::*; use tokio::stream::StreamExt; use sqlx::postgres::PgPoolOptions; use sqlx::Row; -//use sqlx::Done; // .rows_affected() #[macro_use] extern crate lazy_static; use anyhow::{anyhow, bail, Context, Result}; @@ -106,19 +107,50 @@ }; let url: &str = row.try_get("url")?; let mut this_fetch: Option> = None; let iv_hash: Option<&str> = row.try_get("iv_hash")?; let mut posts: BTreeMap, String> = BTreeMap::new(); - let feed = rss::Channel::from_url(url) + let content = reqwest::get(url).await?.bytes().await?; + //let mut content_ = surf::get(url).await.map_err(|err| anyhow!(err))?; + //eprintln!("Data: {:#?}", &content_); + //let content = content_.body_bytes().await.map_err(|err| anyhow!(err))?; + /* + let feed = rss::Channel::read_from(&content[..]) .with_context(|| format!("Problem opening feed url:\n{}", &url))?; for item in feed.items() { let date = match item.pub_date() { Some(feed_date) => DateTime::parse_from_rfc2822(feed_date), None => DateTime::parse_from_rfc3339(&item.dublin_core_ext().unwrap().dates()[0]), }?; let url = item.link().unwrap().to_string(); posts.insert(date.clone(), url.clone()); + }; + */ + match rss::Channel::read_from(&content[..]) { + Ok(feed) => { + for item in feed.items() { + let date = match item.pub_date() { + Some(feed_date) => DateTime::parse_from_rfc2822(feed_date), + None => DateTime::parse_from_rfc3339(&item.dublin_core_ext().unwrap().dates()[0]), + }?; + let url = item.link().unwrap().to_string(); + posts.insert(date.clone(), url.clone()); + }; + }, + Err(err) => match err { + rss::Error::InvalidStartTag => { + let feed = atom_syndication::Feed::read_from(&content[..]) + .with_context(|| format!("Problem opening feed url:\n{}", &url))?; + for item in feed.entries() { + let date = item.published().unwrap(); + let url = item.links()[0].href(); + posts.insert(date.clone(), url.to_string()); + }; + }, + rss::Error::Eof => (), + _ => bail!("Unsupported or mangled content:\n{:#?}\n", err) + } }; for (date, url) in posts.iter() { let mut conn = self.pool.acquire().await .with_context(|| format!("Check post fetch conn:\n{:?}", &self.pool))?; let row = sqlx::query("select exists(select true from rsstg_post where url = $1 and source_id = $2) as exists;")