Compare commits

..

No commits in common. "f76b7194ca8dd21c46a0b52a5d8eb2354c44b3e7" and "e311576f5090c27e5ac35ced63da0d91f00fd812" have entirely different histories.

3 changed files with 10 additions and 34 deletions

View File

@ -9,6 +9,3 @@ 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,9 +2,7 @@ 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,10 +6,7 @@ use std::io::Write;
use std::io::copy; use std::io::copy;
use rss::Channel; use rss::Channel;
use serde::{Serialize, Deserialize}; #[derive(Debug)]
use toml;
#[derive(Debug, Serialize, Deserialize)]
struct Config { struct Config {
url: String, url: String,
author: String, author: String,
@ -18,23 +15,6 @@ 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,
@ -59,14 +39,15 @@ fn write_to_disk(toot: &Toot, path: String, title: String) {
} }
fn main() { fn main() {
// Default config file // Configure RSS url, author and path where the .md will be stored
let default_config = ".config/masto-rss/masto-rss.ini"; let config = Config {
let home = std::env::var("HOME").unwrap(); // url: "https://mastodon.bofhers.es/@oscarmlage.rss",
let cfg = format!("{}/{}", home, default_config); url: "https://mastodon.bofhers.es/tags/micropost.rss".to_string(),
// Read the config file author: "oscarmlage".to_string(),
let mut default_config = Config::default(); path: "temp/".to_string(),
let config = default_config.parse(cfg.to_string()); version: "0.0.1".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();