Almost initial commit

This commit is contained in:
VC
2023-11-07 17:14:49 +01:00
parent e8c2d35e21
commit 8c7e60881b
5 changed files with 444 additions and 38 deletions

View File

@@ -9,6 +9,10 @@ mod mastodon;
use mastodon::get_mastodon_timeline_since;
pub use mastodon::register;
mod utils;
use utils::strip_mastodon_tags;
use dissolve::strip_html_tags;
use rusqlite::Connection;
#[tokio::main]
@@ -25,6 +29,18 @@ pub async fn run(config: &Config) {
.unwrap_or_else(|e| panic!("Cannot get instance: {}", e));
for toot in timeline {
println!("{:?}", &toot.content);
let mut tweet_content = strip_html_tags(
&toot
.content
.replace("</p><p>", "\n\n")
.replace("<br />", "\n"),
)
.join("");
strip_mastodon_tags(&mut tweet_content, &toot.tags).unwrap();
tweet_content = tweet_content.trim_end_matches('\n').trim_end_matches(' ').to_string();
println!("{:?}", tweet_content);
}
}

View File

@@ -1,7 +1,11 @@
use crate::config::MastodonConfig;
use megalodon::{
entities::Status, generator, mastodon::mastodon::Mastodon, megalodon::AppInputOptions,
megalodon::GetHomeTimelineInputOptions, Megalodon,
entities::{Status, StatusVisibility},
generator,
mastodon::mastodon::Mastodon,
megalodon::AppInputOptions,
megalodon::GetHomeTimelineInputOptions,
Megalodon,
};
use std::error::Error;
use std::io::stdin;
@@ -38,6 +42,7 @@ pub async fn get_mastodon_timeline_since(
.clone()
.is_some_and(|r| r == t.account.id)
})
.filter(|t| t.visibility == StatusVisibility::Public)
.collect();
timeline.reverse();

11
src/utils.rs Normal file
View File

@@ -0,0 +1,11 @@
use megalodon::entities::status::Tag;
use std::error::Error;
use regex::Regex;
pub fn strip_mastodon_tags(content: &mut String, tags: &Vec<Tag>) -> Result<(), Box<dyn Error>> {
for tag in tags {
let re = Regex::new(&format!("(?i)(#{} ?)", &tag.name))?;
*content = re.replace(content, "").to_string();
}
Ok(())
}