Initial commit

This commit is contained in:
Leonora Tindall 2022-10-30 09:26:34 -05:00
commit 32999e67d4
Signed by: nora
GPG Key ID: 7A8B52EC67E09AAF
4 changed files with 3087 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/target
mastodon-data.toml

3010
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

13
Cargo.toml Normal file
View File

@ -0,0 +1,13 @@
[package]
name = "northbound-train"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
clap = { version = "4.0.18", features = [ "derive" ] }
eggbug = { version = "0.1.2", features = [ "tokio" ] }
elefren = { version = "0.22.0", features = [ "toml" ] }
tokio = { version = "1.21.2", features = [ "macros", "rt-multi-thread" ] }

62
src/main.rs Normal file
View File

@ -0,0 +1,62 @@
extern crate elefren;
use std::error::Error;
use clap::Parser;
use elefren::prelude::*;
use elefren::helpers::toml;
use elefren::helpers::cli;
use elefren::entities::event::Event;
use eggbug::{Client, Post};
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
struct Args {
/// URL of the mastodon instance you're using
#[arg(short, long, required = true)]
instance: String,
/// Cohost e-mail
#[arg(short, long, required = true)]
email: String,
/// Cohost password
#[arg(short, long, required = true)]
password: String,
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let args = Args::parse();
let mastodon = if let Ok(data) = toml::from_file("mastodon-data.toml") {
Mastodon::from(data)
} else {
register(&args.instance)?
};
// Good! We're now logged into mastodon, check that it worked
mastodon.verify_credentials()?;
// Now log into Cohost
let cohost = Client::new();
let cohost = cohost.login(&args.email, &args.password).await?;
// Now loop over events as they come
for event in mastodon.streaming_user()? {
match event {
}
}
Ok(())
}
fn register(instance: &str) -> Result<Mastodon, Box<dyn Error>> {
let registration = Registration::new(instance)
.client_name("northbound-train")
.build()?;
let mastodon = cli::authenticate(registration)?;
// Save app data for using on the next run.
toml::to_file(&*mastodon, "mastodon-data.toml")?;
Ok(mastodon)
}