Browse Source

Rustfmt

master
Julio Biason 6 years ago
parent
commit
5ec773f984
  1. 28
      src/main.rs

28
src/main.rs

@ -1,19 +1,20 @@
use std::path::Path;
use std::path::PathBuf;
use std::fs::File; use std::fs::File;
use std::io::prelude::*; use std::io::prelude::*;
use std::path::Path;
use std::path::PathBuf;
use elefren::prelude::*; use elefren::entities::attachment::Attachment;
use elefren::entities::status::Status;
use elefren::helpers::cli; use elefren::helpers::cli;
use elefren::helpers::toml; use elefren::helpers::toml;
use elefren::entities::status::Status; use elefren::prelude::*;
use elefren::entities::attachment::Attachment;
use reqwest; use reqwest;
use hyper::Uri; use hyper::Uri;
#[macro_use] use log; #[macro_use]
use log;
use env_logger; use env_logger;
fn main() { fn main() {
@ -33,7 +34,8 @@ fn main() {
info!("Starting up..."); info!("Starting up...");
client client
.favourites().unwrap() .favourites()
.unwrap()
.items_iter() .items_iter()
.take(2) .take(2)
.for_each(move |record| dump_record(record)); .for_each(move |record| dump_record(record));
@ -53,8 +55,7 @@ fn toot_dir(record: &Status) -> PathBuf {
} }
fn create_structure(record: &Status) -> () { fn create_structure(record: &Status) -> () {
std::fs::create_dir_all(toot_dir(record)) std::fs::create_dir_all(toot_dir(record)).expect("Failed to create the storage path");
.expect("Failed to create the storage path");
} }
fn save_content(record: &Status) -> () { fn save_content(record: &Status) -> () {
@ -68,7 +69,8 @@ fn save_content(record: &Status) -> () {
fn save_attachments(record: &Status) -> () { fn save_attachments(record: &Status) -> () {
debug!("Saving attachments of {}...", record.id); debug!("Saving attachments of {}...", record.id);
let base_path = toot_dir(&record); let base_path = toot_dir(&record);
record.media_attachments record
.media_attachments
.iter() .iter()
.for_each(move |x| save_attachment(&x, &base_path)); .for_each(move |x| save_attachment(&x, &base_path));
} }
@ -76,8 +78,10 @@ fn save_attachments(record: &Status) -> () {
fn save_attachment(attachment: &Attachment, base_path: &PathBuf) -> () { fn save_attachment(attachment: &Attachment, base_path: &PathBuf) -> () {
debug!("Saving attachment {}", attachment.url); debug!("Saving attachment {}", attachment.url);
let uri: Uri = attachment.url.parse().expect("Invalid URL"); let uri: Uri = attachment.url.parse().expect("Invalid URL");
let body = reqwest::get(&attachment.url).expect("Failed to connect to server") let body = reqwest::get(&attachment.url)
.text().expect("Failed to retrieve attachment"); .expect("Failed to connect to server")
.text()
.expect("Failed to retrieve attachment");
if let Ok(mut fp) = File::create(base_path.join(uri.path())) { if let Ok(mut fp) = File::create(base_path.join(uri.path())) {
fp.write_all(body.as_bytes()) fp.write_all(body.as_bytes())

Loading…
Cancel
Save