From 949a961c19ba994c3f0846e7b54d9a55a94d7b9a Mon Sep 17 00:00:00 2001 From: Vika Date: Thu, 29 Jul 2021 18:14:30 +0300 Subject: Appease rustfmt, clippy and cargo check --- src/bin/pyindieblog_to_kittybox.rs | 59 ++++++++++++++++++++++++++------------ 1 file changed, 40 insertions(+), 19 deletions(-) (limited to 'src/bin/pyindieblog_to_kittybox.rs') diff --git a/src/bin/pyindieblog_to_kittybox.rs b/src/bin/pyindieblog_to_kittybox.rs index c932e0a..b4e2b97 100644 --- a/src/bin/pyindieblog_to_kittybox.rs +++ b/src/bin/pyindieblog_to_kittybox.rs @@ -1,45 +1,66 @@ -use std::collections::HashMap; -use std::fs::File; -use anyhow::{Result, Context, anyhow}; +use anyhow::{anyhow, Context, Result}; use mobc_redis::redis; use mobc_redis::redis::AsyncCommands; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; +use std::collections::HashMap; +use std::fs::File; #[derive(Default, Serialize, Deserialize)] struct PyindieblogData { posts: Vec, - cards: Vec + cards: Vec, } #[async_std::main] async fn main() -> Result<()> { let mut args = std::env::args(); args.next(); // skip argv[0] which is the name - let redis_uri = args.next().ok_or_else(|| anyhow!("No Redis URI provided"))?; - let client = redis::Client::open(redis_uri.as_str()).with_context(|| format!("Failed to construct Redis client on {}", redis_uri))?; + let redis_uri = args + .next() + .ok_or_else(|| anyhow!("No Redis URI provided"))?; + let client = redis::Client::open(redis_uri.as_str()) + .with_context(|| format!("Failed to construct Redis client on {}", redis_uri))?; - let filename = args.next().ok_or_else(|| anyhow!("No filename provided for export"))?; + let filename = args + .next() + .ok_or_else(|| anyhow!("No filename provided for export"))?; let mut data: Vec; let file = File::create(filename)?; - let mut conn = client.get_async_std_connection().await.with_context(|| "Failed to connect to the Redis server")?; + let mut conn = client + .get_async_std_connection() + .await + .with_context(|| "Failed to connect to the Redis server")?; - data = conn.hgetall::<&str, HashMap>("posts").await? + data = conn + .hgetall::<&str, HashMap>("posts") + .await? .values() - .map(|s| serde_json::from_str::(s) - .with_context(|| format!("Failed to parse the following entry: {:?}", s))) + .map(|s| { + serde_json::from_str::(s) + .with_context(|| format!("Failed to parse the following entry: {:?}", s)) + }) .collect::, anyhow::Error>>() .with_context(|| "Failed to export h-entries from pyindieblog")?; - data.extend(conn.hgetall::<&str, HashMap>("hcards").await? - .values() - .map(|s| serde_json::from_str::(s) - .with_context(|| format!("Failed to parse the following card: {:?}", s))) - .collect::, anyhow::Error>>() - .with_context(|| "Failed to export h-cards from pyindieblog")?); + data.extend( + conn.hgetall::<&str, HashMap>("hcards") + .await? + .values() + .map(|s| { + serde_json::from_str::(s) + .with_context(|| format!("Failed to parse the following card: {:?}", s)) + }) + .collect::, anyhow::Error>>() + .with_context(|| "Failed to export h-cards from pyindieblog")?, + ); - data.sort_by_key(|v| v["properties"]["published"][0].as_str().map(|s| s.to_string())); + data.sort_by_key(|v| { + v["properties"]["published"][0] + .as_str() + .map(|s| s.to_string()) + }); serde_json::to_writer(file, &data)?; -- cgit 1.4.1