mirror of https://github.com/muesli/mastotool
Show reply statistics
This commit is contained in:
parent
88423e10dc
commit
45a29f3be6
9
main.go
9
main.go
|
@ -18,6 +18,7 @@ import (
|
|||
|
||||
var (
|
||||
client *mastodon.Client
|
||||
self *mastodon.Account
|
||||
|
||||
topN = flag.Int("top", 10, "shows the top N items in each category")
|
||||
maxToots = flag.Int("recent", 0, "only account for the N most recent toots (excl replies & boosts)")
|
||||
|
@ -125,9 +126,10 @@ func initClient() {
|
|||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
initClient()
|
||||
self, err := client.GetAccountCurrentUser(context.Background())
|
||||
|
||||
var err error
|
||||
self, err = client.GetAccountCurrentUser(context.Background())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -136,7 +138,7 @@ func main() {
|
|||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
self := accounts[0]
|
||||
self = accounts[0]
|
||||
*/
|
||||
|
||||
stats := &stats{
|
||||
|
@ -148,6 +150,7 @@ func main() {
|
|||
Replies: make(map[string]*tootStat),
|
||||
Mentions: make(map[string]int64),
|
||||
Boosts: make(map[string]int64),
|
||||
Responses: make(map[string]int64),
|
||||
}
|
||||
pb := &goprogressbar.ProgressBar{
|
||||
Text: fmt.Sprintf("Loading toots for %s", self.Username),
|
||||
|
|
25
stats.go
25
stats.go
|
@ -39,6 +39,7 @@ type stats struct {
|
|||
Replies map[string]*tootStat
|
||||
Mentions map[string]int64
|
||||
Boosts map[string]int64
|
||||
Responses map[string]int64
|
||||
}
|
||||
|
||||
func parseToot(status *mastodon.Status, stats *stats) error {
|
||||
|
@ -61,7 +62,15 @@ func parseToot(status *mastodon.Status, stats *stats) error {
|
|||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
replies = int64(len(contexts.Descendants))
|
||||
|
||||
// handle replies for this status
|
||||
for _, d := range contexts.Descendants {
|
||||
if d.Account.ID == self.ID {
|
||||
continue
|
||||
}
|
||||
replies++
|
||||
stats.Responses[d.Account.Acct]++
|
||||
}
|
||||
|
||||
for _, t := range status.Tags {
|
||||
tag := strings.ToLower(t.Name)
|
||||
|
@ -203,10 +212,11 @@ func printTootTable(cols []string, emptyText string, toots []string, tootStats [
|
|||
}
|
||||
|
||||
func printAccountStats(stats *stats) {
|
||||
var likes, boosts int64
|
||||
var likes, boosts, replies int64
|
||||
for _, t := range stats.Toots {
|
||||
likes += t.Likes
|
||||
boosts += t.Boosts
|
||||
replies += t.Replies
|
||||
}
|
||||
|
||||
fmt.Printf("Total toots: %d (excluding replies & boosts)\n", len(stats.Toots))
|
||||
|
@ -225,6 +235,9 @@ func printAccountStats(stats *stats) {
|
|||
fmt.Printf("Boosts per toot: %.2f (total boosts: %d)\n",
|
||||
float64(boosts)/float64(len(stats.Toots)),
|
||||
boosts)
|
||||
fmt.Printf("Replies per toot: %.2f (total replies: %d)\n",
|
||||
float64(replies)/float64(len(stats.Toots)),
|
||||
replies)
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
|
@ -244,6 +257,14 @@ func printInteractionStats(stats *stats) {
|
|||
printTable([]string{"Users you boosted most", "Interactions"},
|
||||
"No interactions found.",
|
||||
ss)
|
||||
|
||||
ss = []kv{}
|
||||
for k, v := range stats.Responses {
|
||||
ss = append(ss, kv{k, v})
|
||||
}
|
||||
printTable([]string{"Users that responded most", "Interactions"},
|
||||
"No interactions found.",
|
||||
ss)
|
||||
}
|
||||
|
||||
func printTootStats(stats *stats) {
|
||||
|
|
Loading…
Reference in New Issue