mirror of
https://github.com/idanoo/go-mastodon-stats
synced 2025-07-02 06:12:19 +00:00
Post weekly instead
This commit is contained in:
parent
f2c7022469
commit
5a884fe3d9
3 changed files with 12 additions and 28 deletions
|
@ -24,6 +24,15 @@ var (
|
||||||
// UserCount metric name
|
// UserCount metric name
|
||||||
METRICNAME_USERCOUNT = "userCount"
|
METRICNAME_USERCOUNT = "userCount"
|
||||||
|
|
||||||
|
// This is hardcoded because.. well configs are annoying
|
||||||
|
SERVICE_LINKS = map[string]string{
|
||||||
|
PIXELFED_IDENTIFIER: "https://pixelfed.nz",
|
||||||
|
MATRIX_IDENTIFIDER: "https://mtrx.nz",
|
||||||
|
MASTODON_IDENTIFIER: "https://mastodon.nz",
|
||||||
|
MOBILIZON_IDENTIFIER: "https://openevents.nz",
|
||||||
|
PEERTUBE_IDENTIFIER: "https//peertube.nz",
|
||||||
|
}
|
||||||
|
|
||||||
// Pixelfed
|
// Pixelfed
|
||||||
PIXELFED_DB_SCHEMA string
|
PIXELFED_DB_SCHEMA string
|
||||||
PIXELFED_USER_QUERY = "SELECT count(*) FROM users WHERE status IS NULL;"
|
PIXELFED_USER_QUERY = "SELECT count(*) FROM users WHERE status IS NULL;"
|
||||||
|
|
|
@ -4,29 +4,10 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/mattn/go-mastodon"
|
"github.com/mattn/go-mastodon"
|
||||||
)
|
)
|
||||||
|
|
||||||
func doTheRegisterThing() {
|
|
||||||
srv, err := mastodon.RegisterApp(context.Background(), &mastodon.AppConfig{
|
|
||||||
Server: fmt.Sprintf("https://%s", MASTODON_INSTANCE_URL),
|
|
||||||
ClientName: MASTODON_CLIENT_NAME,
|
|
||||||
Scopes: "read write follow",
|
|
||||||
RedirectURIs: "urn:ietf:wg:oauth:2.0:oob",
|
|
||||||
Website: "https://github.com/mattn/go-mastodon",
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal("Couldn't register the app. Error: %v\n\nExiting...\n", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Println(
|
|
||||||
"Pls open this link: %s\n\n" + srv.AuthURI +
|
|
||||||
"When completeAdd this to your config under MASTODON_TOKEN and rerun the app")
|
|
||||||
os.Exit(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
func postToMastodon(metrics []metric) {
|
func postToMastodon(metrics []metric) {
|
||||||
if MASTODON_INSTANCE_URL == "" {
|
if MASTODON_INSTANCE_URL == "" {
|
||||||
log.Printf("Skipping posting to mastodon. Missing configuration")
|
log.Printf("Skipping posting to mastodon. Missing configuration")
|
||||||
|
@ -46,11 +27,11 @@ func postToMastodon(metrics []metric) {
|
||||||
|
|
||||||
// Build status
|
// Build status
|
||||||
startOfDay := getStartofDay()
|
startOfDay := getStartofDay()
|
||||||
msg := fmt.Sprintf("User counts for %s :laserkiwi:\n\n", startOfDay.String())
|
msg := fmt.Sprintf("Weekly user counts @ %s :laserkiwi:\n\n", startOfDay.String())
|
||||||
for _, m := range metrics {
|
for _, m := range metrics {
|
||||||
msg = msg + getPrintableString(m) + "\n"
|
msg = msg + getPrintableString(m) + "\n"
|
||||||
}
|
}
|
||||||
msg = msg + "\n\n" + "#DailyStats"
|
msg = msg + "\n\n" + "#WeeklyStats"
|
||||||
|
|
||||||
toot := &mastodon.Toot{
|
toot := &mastodon.Toot{
|
||||||
Status: msg,
|
Status: msg,
|
||||||
|
|
|
@ -4,9 +4,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"golang.org/x/text/cases"
|
|
||||||
"golang.org/x/text/language"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Stores out metric/row data
|
// Stores out metric/row data
|
||||||
|
@ -117,8 +114,5 @@ func getUserCounts() ([]metric, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPrintableString(m metric) string {
|
func getPrintableString(m metric) string {
|
||||||
caser := cases.Title(language.English)
|
return fmt.Sprintf("%s: %d", SERVICE_LINKS[m.Service], m.MetricValue)
|
||||||
titleStr := caser.String(m.Service)
|
|
||||||
|
|
||||||
return fmt.Sprintf("%s: %d", titleStr, m.MetricValue)
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue