releases 0.0.1

deepl
syui 1 year ago
parent f150a352ed
commit b85832a6d7
Signed by: syui
GPG Key ID: 67AC97A939D3EA19

@ -1,5 +0,0 @@
export TOKEN=''
export CLIENT_ID=''
export CLIENT_SECRET=''
export REDIRECT=''
export BASE='https://mstdn.syui.cf'

2
.gitignore vendored

@ -1,3 +1,5 @@
.env
Cargo.lock
target
config.toml
*.txt

@ -8,4 +8,11 @@ edition = "2021"
seahorse = "1.1.2"
dotenv = "0.15"
mammut = "0.13.0"
serde_derive = "1.0"
serde_json = "1.0"
toml = "*"
serde = "*"
envy = "*"
config = { git = "https://github.com/mehcode/config-rs", branch = "master" }
lazy_static = "1.0"
once_cell = "*"

@ -0,0 +1,5 @@
token = ""
client_id = ""
client_secret = ""
redirect = "localhost"
base = "https://mstdn.syui.cf"

@ -1,7 +1,12 @@
mastodon cli client.
```sh
$ cp config.toml.example config.toml
$ vim config.toml
$ cargo run
$ ./target/debug/msr s
```
mastodon api lib : https://docs.rs/mammut/latest/mammut

@ -0,0 +1,22 @@
use config::{Config, ConfigError, File};
use serde_derive::Deserialize;
use std::borrow::Cow;
#[derive(Debug, Deserialize)]
#[allow(unused)]
pub struct Data {
pub base: Cow<'static, str>,
pub token: Cow<'static, str>,
pub client_id: Cow<'static, str>,
pub client_secret: Cow<'static, str>,
pub redirect: Cow<'static, str>,
}
impl Data {
pub fn new() -> Result<Self, ConfigError> {
let s = Config::builder()
.add_source(File::with_name("config"))
.build()?;
s.try_deserialize()
}
}

@ -1,19 +1,73 @@
use std::env;
pub mod data;
use data::Data as Datas;
use mammut::{Data, Mastodon, StatusBuilder};
use seahorse::{App, Command, Context};
use mammut::{Data, Mastodon};
fn main() -> mammut::Result<()> {
fn main() {
let args: Vec<String> = env::args().collect();
let app = App::new(env!("CARGO_PKG_NAME"))
.author(env!("CARGO_PKG_AUTHORS"))
.version(env!("CARGO_PKG_VERSION"))
.usage("cli_tool [command] [x] [y]")
.command(
Command::new("s")
.usage("msr s")
.action(s),
)
.command(
Command::new("p")
.usage("msr p {}")
.action(p),
)
.command(
Command::new("t")
.usage("msr t")
.action(t),
)
;
app.run(args);
}
fn token() -> Mastodon {
let data = Datas::new().unwrap();
let data = Data {
base: env::var("BASE").unwrap().into(),
client_id: env::var("CLIENT_ID").unwrap().into(),
client_secret: env::var("CLIENT_SECRET").unwrap().into(),
redirect: env::var("REDIRECT").unwrap().into(),
token: env::var("TOKEN").unwrap().into(),
base: data.base,
token: data.token,
client_id: data.client_id,
client_secret: data.client_secret,
redirect: data.redirect,
};
let t = Mastodon::from_data(data);
return t;
}
fn s(_c: &Context) {
let mastodon = token();
let tl = mastodon.verify_credentials();
println!("{:#?}", tl);
}
let mastodon = Mastodon::from_data(data);
println!("{:?}", mastodon.get_home_timeline()?.initial_items);
fn timeline() -> mammut::Result<()> {
let mastodon = token();
let length = &mastodon.get_home_timeline()?.initial_items.len();
for n in 0..*length {
let user = &mastodon.get_home_timeline()?.initial_items[n].account.username;
let body = &mastodon.get_home_timeline()?.initial_items[n].content;
println!("{} {:?}", user, body);
}
Ok(())
}
fn t(_c: &Context) {
let t = timeline().unwrap();
println!("{:#?}", t);
}
fn p(c: &Context) {
let mastodon = token();
let message = c.args[0].to_string();
let status_b = StatusBuilder::new(format!("{}", message));
let post = mastodon.new_status(status_b);
println!("{:?}", post);
}

Loading…
Cancel
Save