initial commit

This commit is contained in:
postscriptum 2025-07-01 17:39:30 +03:00
commit 63f53528dc
10 changed files with 443 additions and 0 deletions

76
src/main.rs Normal file
View file

@ -0,0 +1,76 @@
mod config;
mod nex;
mod snac;
use anyhow::Result;
use nex::Nex;
use snac::Snac;
fn main() -> Result<()> {
use clap::Parser;
use config::Config;
let c = Config::parse();
let n = Nex::init(
c.target,
c.format_filename,
c.format_updated,
c.format_content,
&c.user,
)?;
let s = Snac::init(c.source, c.user)?;
println!("export begin...");
let (mut u, mut t) = sync(&s, &n)?;
match c.rotate {
Some(r) => loop {
println!("queue completed (updated: {u} / total: {t}), await {r} seconds to rotate...");
std::thread::sleep(std::time::Duration::from_secs(r));
(u, t) = sync(&s, &n)?;
},
None => println!("export completed (updated: {u} / total: {t})."),
}
Ok(())
}
fn sync(snac: &Snac, nex: &Nex) -> Result<(usize, usize)> {
let mut t = 0; // total
let mut u = 0; // updated
for user in &snac.users {
println!("\tsync profile for `{}`...", user.name);
for post in user.public()? {
t += 1;
// skip non authorized content
if let Some(content) = post.source_content {
println!("\t\tsync post `{}`...", post.id);
nex.sync(
&user.name,
content,
post.url,
post.attachment.map(|a| {
let mut attachments = Vec::with_capacity(a.len());
for attachment in a {
attachments.push((
attachment.name,
attachment.media_type,
attachment.url,
))
}
attachments
}),
post.tag.map(|t| {
let mut tags = Vec::with_capacity(t.len());
for tag in t {
tags.push(tag.name)
}
tags
}),
(post.published, post.updated),
)?;
u += 1;
}
}
}
Ok((t, u))
}