Compare commits

...

3 Commits

@ -27,6 +27,10 @@ impl Data {
pub struct Notify {
pub notifications: Vec<Notifications>
}
#[derive(Serialize, Deserialize)]
pub struct Timeline {
pub feed: Vec<Feed>
}
#[derive(Serialize, Deserialize)]
#[allow(non_snake_case)]
@ -37,7 +41,7 @@ pub struct Notifications {
pub reason: String,
pub record: Record,
pub isRead: bool,
pub indexedAt: String
pub indexedAt: String,
}
#[derive(Serialize, Deserialize)]
@ -68,6 +72,8 @@ pub struct Viewer {
pub struct Token {
pub did: String,
pub accessJwt: String,
pub refreshJwt: String,
pub handle: String,
}
#[derive(Serialize, Deserialize)]
@ -78,10 +84,25 @@ pub struct Record {
}
#[derive(Serialize, Deserialize)]
struct Post {
pub did: String,
pub collection: String,
pub record: Record
#[allow(non_snake_case)]
pub struct Feed {
pub post: Post,
}
#[derive(Serialize, Deserialize)]
#[allow(non_snake_case)]
pub struct Post {
pub did: Option<String>,
pub uri: String,
pub collection: Option<String>,
pub record: Record,
pub author: Author,
pub reason: Option<String>,
pub indexedAt: String,
pub replyCount: i32,
pub repostCount: i32,
pub upvoteCount: i32,
pub downvoteCount: i32,
}
#[derive(Serialize, Deserialize)]
@ -98,3 +119,4 @@ pub struct Handle {
pub struct Did {
pub did: String
}

@ -19,6 +19,7 @@ use data::Token as Token;
use data::Did as Did;
use data::Cid as Cid;
use data::Handle as Handle;
use crate::data::Timeline;
use std::io;
use std::io::Write;
@ -139,7 +140,17 @@ fn main() {
.usage("atr t")
.description("timeline\n\t\t\t$ atr t")
.alias("t")
.action(t),
.action(t)
.flag(
Flag::new("latest", FlagType::Bool)
.description("latest flag\n\t\t\t$ atr t -l")
.alias("l"),
)
.flag(
Flag::new("json", FlagType::Bool)
.description("count flag\n\t\t\t$ atr t -j")
.alias("c"),
)
)
.command(
Command::new("media")
@ -161,12 +172,12 @@ fn main() {
.alias("n")
.action(n)
.flag(
Flag::new("latest", FlagType::String)
.description("latest flag\n\t\t\t$ atr n -l 0")
Flag::new("latest", FlagType::Bool)
.description("latest flag\n\t\t\t$ atr n -l")
.alias("l"),
)
.flag(
Flag::new("count", FlagType::String)
Flag::new("count", FlagType::Int)
.description("count flag\n\t\t\t$ atr n -c 0")
.alias("c"),
)
@ -248,17 +259,21 @@ fn f(c: &Context) {
#[tokio::main]
async fn aa() -> reqwest::Result<()> {
let file = "/.config/atr/token.json";
let mut f = shellexpand::tilde("~").to_string();
f.push_str(&file);
let data = Datas::new().unwrap();
let data = Datas {
host: data.host,
user: data.user,
pass: data.pass,
};
let url = "https://".to_owned() + &data.host + &"/xrpc/com.atproto.session.create";
let handle = data.user;
//let handle = data.user + &"." + &data.host;
let handle = data.user;
let mut map = HashMap::new();
let url = "https://".to_owned() + &data.host + &"/xrpc/com.atproto.session.create";
map.insert("handle", &handle);
map.insert("password", &data.pass);
let client = reqwest::Client::new();
@ -271,11 +286,6 @@ async fn aa() -> reqwest::Result<()> {
.await?;
let j = Json::from_str(&res).unwrap();
let j = j.to_string();
let file = "/.config/atr/token.json";
let mut f = shellexpand::tilde("~").to_string();
f.push_str(&file);
let mut f = fs::File::create(f).unwrap();
if j != "" {
f.write_all(&j.as_bytes()).unwrap();
@ -388,7 +398,7 @@ fn p(c: &Context) {
}
#[tokio::main]
async fn tt(_c: &Context) -> reqwest::Result<()> {
async fn tt(c: &Context) -> reqwest::Result<()> {
let file = "/.config/atr/token.json";
let mut f = shellexpand::tilde("~").to_string();
f.push_str(&file);
@ -410,13 +420,38 @@ async fn tt(_c: &Context) -> reqwest::Result<()> {
.text()
.await?;
println!("{}", j);
let timeline: Timeline = serde_json::from_str(&j).unwrap();
let n = timeline.feed;
let mut map = HashMap::new();
if c.bool_flag("json") {
println!("{}", j);
} else if c.bool_flag("latest") {
map.insert("handle", &n[0].post.author.handle);
map.insert("uri", &n[0].post.uri);
if ! n[0].post.record.text.is_none() {
map.insert("text", &n[0].post.record.text.as_ref().unwrap());
}
println!("{:?}", map);
} else {
let length = &n.len();
for i in 0..*length {
println!("@{}", n[i].post.author.handle);
if ! n[i].post.record.text.is_none() {
println!("text : {}", n[i].post.record.text.as_ref().unwrap());
}
println!("⚡️ [{}]\t⭐ [{}]\t🌈 [{}]", n[i].post.replyCount,n[i].post.replyCount, n[i].post.upvoteCount);
println!("{}", "---------");
}
}
Ok(())
}
fn t(_c: &Context) {
fn t(c: &Context) {
aa().unwrap();
tt(_c).unwrap();
tt(c).unwrap();
}
#[tokio::main]
@ -749,7 +784,7 @@ async fn nn(c: &Context) -> reqwest::Result<()> {
user: data.user,
pass: data.pass,
};
if let Ok(_latest) = c.string_flag("latest") {
if let Ok(_get) = c.string_flag("get") {
let url = "https://".to_owned() + &data.host + &"/xrpc/app.bsky.notification.getCount";
let client = reqwest::Client::new();
let res = client
@ -760,35 +795,45 @@ async fn nn(c: &Context) -> reqwest::Result<()> {
.text()
.await?;
println!("{}", res);
} else if let Ok(_count) = c.string_flag("count") {
let url = "https://".to_owned() + &data.host + &"/xrpc/app.bsky.notification.list";
let client = reqwest::Client::new();
let res = client
.get(url)
.header("Authorization", "Bearer ".to_owned() + &token)
.send()
.await?
.text()
.await?;
let notify: Notify = serde_json::from_str(&res).unwrap();
let n = notify.notifications;
}
println!("handle : {}", n[0].author.handle);
println!("createdAt : {}", n[0].record.createdAt);
println!("uri : {}", n[0].uri);
println!("cid : {}", n[0].cid);
println!("text : {}", n[0].record.text.as_ref().unwrap());
let url = "https://".to_owned() + &data.host + &"/xrpc/app.bsky.notification.list";
let client = reqwest::Client::new();
let res = client
.get(url)
.header("Authorization", "Bearer ".to_owned() + &token)
.send()
.await?
.text()
.await?;
let notify: Notify = serde_json::from_str(&res).unwrap();
let n = notify.notifications;
let mut map = HashMap::new();
if c.bool_flag("latest") {
map.insert("handle", &n[0].author.handle);
map.insert("createdAt", &n[0].record.createdAt);
map.insert("uri", &n[0].uri);
map.insert("cid", &n[0].cid);
if ! n[0].record.text.is_none() {
map.insert("text", &n[0].record.text.as_ref().unwrap());
}
println!("{:?}", map);
} else if let Ok(count) = c.int_flag("count") {
let length = &n.len();
for i in 0..*length {
if i < count.try_into().unwrap() {
println!("handle : {}", n[i].author.handle);
println!("createdAt : {}", n[i].record.createdAt);
println!("uri : {}", n[i].uri);
println!("cid : {}", n[i].cid);
if ! n[i].record.text.is_none() {
println!("text : {}", n[i].record.text.as_ref().unwrap());
}
println!("{}", "---------");
}
}
} else {
let url = "https://".to_owned() + &data.host + &"/xrpc/app.bsky.notification.list";
let client = reqwest::Client::new();
let res = client
.get(url)
.header("Authorization", "Bearer ".to_owned() + &token)
.send()
.await?
.text()
.await?;
println!("{}", res);
}
Ok(())

Loading…
Cancel
Save