Add: config file
This commit is contained in:
parent
b95ff9d6f8
commit
f76b7194ca
@ -9,3 +9,6 @@ edition = "2021"
|
|||||||
reqwest = { version = "0.11.12", features = ["blocking"] }
|
reqwest = { version = "0.11.12", features = ["blocking"] }
|
||||||
rss = "2.0.1"
|
rss = "2.0.1"
|
||||||
chrono = "0.4.23"
|
chrono = "0.4.23"
|
||||||
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
|
serde_json = "1.0.40"
|
||||||
|
toml = "0.4.2"
|
||||||
|
39
src/main.rs
39
src/main.rs
@ -6,7 +6,10 @@ use std::io::Write;
|
|||||||
use std::io::copy;
|
use std::io::copy;
|
||||||
use rss::Channel;
|
use rss::Channel;
|
||||||
|
|
||||||
#[derive(Debug)]
|
use serde::{Serialize, Deserialize};
|
||||||
|
use toml;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
struct Config {
|
struct Config {
|
||||||
url: String,
|
url: String,
|
||||||
author: String,
|
author: String,
|
||||||
@ -15,6 +18,23 @@ struct Config {
|
|||||||
description: String,
|
description: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Config {
|
||||||
|
pub fn default() -> Config {
|
||||||
|
Config {
|
||||||
|
url: "https://mastodon.bofhers.es/tags/micropost.rss".to_string(),
|
||||||
|
author: "oscarmlage".to_string(),
|
||||||
|
path: "temp/".to_string(),
|
||||||
|
version: "0.0.1".to_string(),
|
||||||
|
description: "Just another tool to convert RSS from Mastodon to Markdown".to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn parse(&mut self, config_file: String) -> Config {
|
||||||
|
let i = std::fs::read_to_string(config_file).expect("Error reading the file");
|
||||||
|
let myconfig: Self = toml::from_str(&i).unwrap();
|
||||||
|
myconfig
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct Toot {
|
struct Toot {
|
||||||
title: String,
|
title: String,
|
||||||
@ -39,15 +59,14 @@ fn write_to_disk(toot: &Toot, path: String, title: String) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// Configure RSS url, author and path where the .md will be stored
|
// Default config file
|
||||||
let config = Config {
|
let default_config = ".config/masto-rss/masto-rss.ini";
|
||||||
// url: "https://mastodon.bofhers.es/@oscarmlage.rss",
|
let home = std::env::var("HOME").unwrap();
|
||||||
url: "https://mastodon.bofhers.es/tags/micropost.rss".to_string(),
|
let cfg = format!("{}/{}", home, default_config);
|
||||||
author: "oscarmlage".to_string(),
|
// Read the config file
|
||||||
path: "temp/".to_string(),
|
let mut default_config = Config::default();
|
||||||
version: "0.0.1".to_string(),
|
let config = default_config.parse(cfg.to_string());
|
||||||
description: "Just another tool to convert RSS from Mastodon to Markdown".to_string(),
|
|
||||||
};
|
|
||||||
println!("\n✨ masto-rss v.{} - {}\n", config.version, config.description);
|
println!("\n✨ masto-rss v.{} - {}\n", config.version, config.description);
|
||||||
let rss = reqwest::blocking::get(config.url).unwrap().bytes();
|
let rss = reqwest::blocking::get(config.url).unwrap().bytes();
|
||||||
let rss2 = rss.unwrap();
|
let rss2 = rss.unwrap();
|
||||||
|
Loading…
Reference in New Issue
Block a user