mirror of
https://github.com/idanoo/go-mastodon-stats
synced 2025-07-01 05:42:19 +00:00
38 lines
707 B
Go
38 lines
707 B
Go
package gomastodonstats
|
|
|
|
import (
|
|
"log"
|
|
"sort"
|
|
"time"
|
|
)
|
|
|
|
func Run() {
|
|
log.Println("Fetching counts")
|
|
|
|
// Get Counts
|
|
metrics, err := getUserCounts()
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
// Write to DB
|
|
updatedMetrics := persistMetrics(metrics)
|
|
if len(updatedMetrics) > 0 {
|
|
// Sort by counts!
|
|
sort.Slice(updatedMetrics, func(i, j int) bool {
|
|
return updatedMetrics[i].MetricValue > updatedMetrics[j].MetricValue
|
|
})
|
|
|
|
sendToMatrix(updatedMetrics)
|
|
|
|
// Only post weekly here
|
|
localTime, err := time.LoadLocation(TIMEZONE)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
weekday := time.Now().Local().In(localTime).Weekday()
|
|
if weekday == time.Monday {
|
|
postToMastodon(updatedMetrics)
|
|
}
|
|
}
|
|
}
|