twixter

A twtxt command line client in Rust

git clone git://git.shimmy1996.com/twixter.git
commit a0a27aa9d8e216818a1e5d06a1cb41543f656f2d
parent 1f72b5524eb94d18b9f76418447978b6a1c37236
Author: Shimmy Xu <shimmy.xu@shimmy1996.com>
Date:   Sun, 15 Sep 2019 11:48:58 -0400

Skip sources that cannot be reached

Diffstat:
Msrc/timeline.rs | 15++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/src/timeline.rs b/src/timeline.rs
@@ -35,16 +35,17 @@ pub fn timeline(config: &Config, _subcommand: &ArgMatches) {
 /// Parses given twtxt url, returns a Vec of (post_time, content).
 fn parse_twtxt(twturl: &str) -> Vec<(DateTime<FixedOffset>, String)> {
     let client = Client::new();
-    let resp = client.get(twturl).send().unwrap().text().unwrap();
     let mut tweets = Vec::new();
 
-    for line in resp.lines() {
-        if let Some(seperator_idx) = line.find('\t') {
-            if let Ok(tweet_time) = DateTime::parse_from_rfc3339(&line[..seperator_idx]) {
-                tweets.push((tweet_time, line[seperator_idx + 1..].to_owned()));
+    if let Ok(resp_text) = client.get(twturl).send().and_then(|mut resp| resp.text()) {
+        for line in resp_text.lines() {
+            if let Some(seperator_idx) = line.find('\t') {
+                if let Ok(tweet_time) = DateTime::parse_from_rfc3339(&line[..seperator_idx]) {
+                    tweets.push((tweet_time, line[seperator_idx + 1..].to_owned()));
+                };
             };
-        };
-    }
+        }
+    };
 
     tweets
 }