mirror of
https://framagit.org/veretcle/oolatoocs.git
synced 2025-07-20 20:41:17 +02:00
Almost initial commit
This commit is contained in:
18
src/lib.rs
18
src/lib.rs
@@ -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);
|
||||
}
|
||||
}
|
||||
|
@@ -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
11
src/utils.rs
Normal 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(())
|
||||
}
|
Reference in New Issue
Block a user