Compare commits

..

2 Commits

Author SHA1 Message Date
f76b7194ca Add: config file 2022-11-18 22:07:47 +01:00
b95ff9d6f8 Imp: add clear to make actions 2022-11-18 22:07:35 +01:00
3 changed files with 34 additions and 10 deletions

View File

@ -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"

View File

@ -2,7 +2,9 @@ bash:
docker-compose run --rm dev docker-compose run --rm dev
build: build:
clear
cargo build cargo build
run: run:
clear
cargo run cargo run

View File

@ -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();