update timeline layout

main
syui 3 months ago
parent dad5f3c977
commit b668d450d2
Signed by: syui
GPG Key ID: 67AC97A939D3EA19

@ -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)]
@ -80,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)]
@ -100,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")
@ -387,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);
@ -409,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]

Loading…
Cancel
Save