aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Garrelou <simon.garrelou@gmail.com>2023-07-07 17:00:29 +0200
committerSimon Garrelou <simon.garrelou@gmail.com>2023-07-07 17:00:29 +0200
commit12e14bc1f35137864840433e36b66b219a818371 (patch)
tree7efdab53201ebb202d98e405b7339da0ea0bbee7
parent377bfd98cea99483eda2d659d8f1423761ea25ed (diff)
downloadrss-12e14bc1f35137864840433e36b66b219a818371.tar.gz
rss-12e14bc1f35137864840433e36b66b219a818371.zip
Use blocking reqwest
-rw-r--r--Cargo.lock22
-rw-r--r--Cargo.toml3
-rw-r--r--src/fetch.rs8
-rw-r--r--src/main.rs9
4 files changed, 16 insertions, 26 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 4555e1d..1c63bbb 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -460,6 +460,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
460checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" 460checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c"
461 461
462[[package]] 462[[package]]
463name = "futures-io"
464version = "0.3.28"
465source = "registry+https://github.com/rust-lang/crates.io-index"
466checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964"
467
468[[package]]
463name = "futures-sink" 469name = "futures-sink"
464version = "0.3.28" 470version = "0.3.28"
465source = "registry+https://github.com/rust-lang/crates.io-index" 471source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -478,9 +484,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
478checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" 484checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533"
479dependencies = [ 485dependencies = [
480 "futures-core", 486 "futures-core",
487 "futures-io",
481 "futures-task", 488 "futures-task",
489 "memchr",
482 "pin-project-lite", 490 "pin-project-lite",
483 "pin-utils", 491 "pin-utils",
492 "slab",
484] 493]
485 494
486[[package]] 495[[package]]
@@ -1173,7 +1182,6 @@ dependencies = [
1173 "reqwest", 1182 "reqwest",
1174 "rss 2.0.4", 1183 "rss 2.0.4",
1175 "tera", 1184 "tera",
1176 "tokio",
1177] 1185]
1178 1186
1179[[package]] 1187[[package]]
@@ -1471,22 +1479,10 @@ dependencies = [
1471 "num_cpus", 1479 "num_cpus",
1472 "pin-project-lite", 1480 "pin-project-lite",
1473 "socket2", 1481 "socket2",
1474 "tokio-macros",
1475 "windows-sys 0.48.0", 1482 "windows-sys 0.48.0",
1476] 1483]
1477 1484
1478[[package]] 1485[[package]]
1479name = "tokio-macros"
1480version = "2.1.0"
1481source = "registry+https://github.com/rust-lang/crates.io-index"
1482checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e"
1483dependencies = [
1484 "proc-macro2",
1485 "quote",
1486 "syn 2.0.18",
1487]
1488
1489[[package]]
1490name = "tokio-native-tls" 1486name = "tokio-native-tls"
1491version = "0.3.1" 1487version = "0.3.1"
1492source = "registry+https://github.com/rust-lang/crates.io-index" 1488source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index f9be050..37c8aed 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -11,7 +11,6 @@ anyhow = "1.0.71"
11chrono = "0.4.26" 11chrono = "0.4.26"
12clap = { version = "4.3.4", features = ["derive"] } 12clap = { version = "4.3.4", features = ["derive"] }
13regex = "1.8.4" 13regex = "1.8.4"
14reqwest = "0.11.18" 14reqwest = { version = "0.11.18", features = ["blocking"] }
15rss = { version = "2.0.4", features = ["serde"] } 15rss = { version = "2.0.4", features = ["serde"] }
16tera = "1.19.0" 16tera = "1.19.0"
17tokio = { version = "1.28.2", features = ["macros", "rt-multi-thread"] }
diff --git a/src/fetch.rs b/src/fetch.rs
index 3d619c1..83388b8 100644
--- a/src/fetch.rs
+++ b/src/fetch.rs
@@ -1,11 +1,9 @@
1use anyhow::Result; 1use anyhow::Result;
2use rss::Channel; 2use rss::Channel;
3 3
4pub async fn run(url: String) -> Result<Channel> { 4pub fn run(url: String) -> Result<Channel> {
5 let content = reqwest::get(url) 5 let content = reqwest::blocking::get(url)?
6 .await? 6 .bytes()?;
7 .bytes()
8 .await?;
9 7
10 let channel = Channel::read_from(&content[..])?; 8 let channel = Channel::read_from(&content[..])?;
11 Ok(channel) 9 Ok(channel)
diff --git a/src/main.rs b/src/main.rs
index 7fa00f7..406eff1 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,7 +1,6 @@
1use clap::{Subcommand, Parser, ValueEnum}; 1use clap::{Subcommand, Parser, ValueEnum};
2use rss::Channel; 2use rss::Channel;
3use tokio; 3use std::process::exit;
4use std::{process::exit, io::Write};
5 4
6mod fetch; 5mod fetch;
7mod sort; 6mod sort;
@@ -71,14 +70,12 @@ pub enum Order {
71 Asc, 70 Asc,
72 Desc 71 Desc
73} 72}
74 73fn main() {
75#[tokio::main]
76async fn main() {
77 let args = Args::parse(); 74 let args = Args::parse();
78 75
79 match args.command { 76 match args.command {
80 Commands::Fetch { url } => { 77 Commands::Fetch { url } => {
81 match fetch::run(url).await { 78 match fetch::run(url) {
82 Ok(c) => { 79 Ok(c) => {
83 c.pretty_write_to(std::io::stdout(), b' ', 2).unwrap(); 80 c.pretty_write_to(std::io::stdout(), b' ', 2).unwrap();
84 }, 81 },