This commit is contained in:
idanoo 2023-02-13 08:22:12 +13:00
parent 43514cc0b0
commit adfcf44890
Signed by: idanoo
GPG key ID: 387387CDBC02F132
3 changed files with 36 additions and 10 deletions

View file

@ -3,7 +3,6 @@ package gomastodonstats
import ( import (
"log" "log"
"sort" "sort"
"time"
) )
func Run() { func Run() {
@ -23,16 +22,16 @@ func Run() {
return updatedMetrics[i].MetricValue > updatedMetrics[j].MetricValue return updatedMetrics[i].MetricValue > updatedMetrics[j].MetricValue
}) })
sendToMatrix(updatedMetrics) // sendToMatrix(updatedMetrics)
// Only post weekly here // Only post weekly here
localTime, err := time.LoadLocation(TIMEZONE) // localTime, err := time.LoadLocation(TIMEZONE)
if err != nil { // if err != nil {
log.Fatal(err) // log.Fatal(err)
} // }
weekday := time.Now().Local().In(localTime).Weekday() // weekday := time.Now().Local().In(localTime).Weekday()
if weekday == time.Monday { // if weekday == time.Monday {
postToMastodon(updatedMetrics) // postToMastodon(updatedMetrics)
} // }
} }
} }

View file

@ -162,6 +162,13 @@ func getLastMetric(serviceName string) int {
func getLastWeekMetric(serviceName string) int { func getLastWeekMetric(serviceName string) int {
monday := getStartofDayMonday() monday := getStartofDayMonday()
log.Printf(
"SELECT metric_value FROM %s WHERE metric_name = '%s' AND service = '%s' AND metric_time = '%s' LIMIT 1",
POSTGRESQL_STATS_TABLE,
METRICNAME_USERCOUNT,
serviceName,
monday,
)
val, err := runIntQuery( val, err := runIntQuery(
POSTGRESQL_STATS_DB, POSTGRESQL_STATS_DB,
fmt.Sprintf( fmt.Sprintf(

20
test.go Normal file
View file

@ -0,0 +1,20 @@
package main
import (
"log"
"time"
)
func main() {
localTime, err := time.LoadLocation("Pacific/Auckland")
if err != nil {
log.Fatal(err)
}
// Iterate until Monday!
t := time.Now().In(localTime)
for t.Weekday() != time.Monday {
t = t.AddDate(0, 0, -1)
}
year, month, day := t.Date()
log.Println(time.Date(year, month, day, 0, 0, 0, 0, t.Location()).String())
}