--- a/README.md Mon Mar 19 15:06:17 2018 +0100
+++ b/README.md Mon Mar 19 15:26:43 2018 +0100
@@ -232,11 +232,6 @@
% madonctl accounts --account-id 1 followers --template '{{.acct}}{{"\n"}}'
```
-Number of users on current instance (statistics from instances.mastodon.xyz API):
-```
-madonctl instance --stats --template '{{printf "%v\n" .users}}'
-```
-
You can write and use [themes](templates) as well:
```
madonctl --theme=ansi timeline
--- a/cmd/instance.go Mon Mar 19 15:06:17 2018 +0100
+++ b/cmd/instance.go Mon Mar 19 15:26:43 2018 +0100
@@ -6,21 +6,11 @@
package cmd
import (
- "context"
"os"
- "strings"
- "github.com/m0t0k1ch1/gomif"
- "github.com/pkg/errors"
"github.com/spf13/cobra"
)
-var instanceOpts struct {
- stats bool
- server string
- start, end int64
-}
-
// timelinesCmd represents the timelines command
var instanceCmd = &cobra.Command{
Use: "instance",
@@ -28,40 +18,20 @@
Long: `Display instance information
This command display the instance information returned by the server.
-
-With '--stats', the instances.mastodon.xyz API is queried and instance
-statistics will be returned (the instance server can be specified).
-To get a range of statistics, both '--start' and '--end' should be provided
-with UNIX timestamps (e.g. "date +%s").
`,
RunE: instanceRunE,
- Example: ` madonctl instance
- madonctl instance -i mastodon.social
- madonctl instance --stats
- madonctl instance --stats --start 1493565000 --end 1493566000
- madonctl instance --stats --server mastodon.social --template '{{.Users}}'`,
}
func init() {
RootCmd.AddCommand(instanceCmd)
-
- instanceCmd.Flags().BoolVar(&instanceOpts.stats, "stats", false, "Display server statistics (from instances.mastodon.xyz)")
- instanceCmd.Flags().StringVar(&instanceOpts.server, "server", "", "Display statistics for a specific server (for --stats)")
- instanceCmd.Flags().Int64Var(&instanceOpts.start, "start", 0, "Start timestamp (for --stats)")
- instanceCmd.Flags().Int64Var(&instanceOpts.end, "end", 0, "End timestamp (for --stats)")
}
func instanceRunE(cmd *cobra.Command, args []string) error {
- opt := instanceOpts
-
- if opt.stats {
- return instanceStats()
+ if err := madonInit(false); err != nil {
+ return err
}
// Get current instance data through the API
- if err := madonInit(false); err != nil {
- return err
- }
i, err := gClient.GetCurrentInstance()
if err != nil {
errPrint("Error: %s", err.Error())
@@ -75,56 +45,3 @@
}
return p.printObj(i)
}
-
-func instanceStats() error {
- opt := instanceOpts
-
- // Get instance statistics using gomif
- if opt.server == "" {
- if err := madonInit(false); err != nil {
- return err
- }
- opt.server = strings.TrimLeft(gClient.InstanceURL, "https://")
- }
-
- if opt.server == "" {
- return errors.New("no instance server name")
- }
-
- client := gomif.NewClient()
- var obj interface{}
- var err error
-
- if opt.start > 0 && opt.end > 0 {
- var isl []*gomif.InstanceStatus
- isl, err = client.FetchInstanceStatuses(
- context.Background(),
- opt.server, opt.start, opt.end,
- )
- obj = isl
- } else if opt.start > 0 || opt.end > 0 {
- return errors.New("invalid parameters: missing timestamp")
- } else {
- var is *gomif.InstanceStatus
- is, err = client.FetchLastInstanceStatus(
- context.Background(),
- opt.server,
- 3600, // span (sec)
- )
- obj = is
- }
- if err != nil {
- errPrint("Error: %s", err.Error())
- os.Exit(1)
- }
- if obj == nil {
- return nil
- }
-
- p, err := getPrinter()
- if err != nil {
- errPrint("Error: %s", err.Error())
- os.Exit(1)
- }
- return p.printObj(obj)
-}
--- a/examples/instance_statistics.sh Mon Mar 19 15:06:17 2018 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,22 +0,0 @@
-#! /bin/sh
-#
-# Instance statistics for a given period (default: the last hour)
-#
-# Usage: $0 [startdate [enddate]]
-# (The timestamps must be accepted by date -d)
-#
-# Examples:
-# ./instance_statistics.sh
-# ./instance_statistics.sh "30 minutes ago"
-# ./instance_statistics.sh "1 hour ago" "30 minutes ago"
-# ./instance_statistics.sh "2017-04-30 18:55:00" "2017-04-30 19:05:00"
-#
-# Mikael
-
-start=${1:-1 hour ago}
-end=${2:-now}
-
-TMPL='{{.date | fromunix}} {{.instance_name}}: {{printf "%.0f users, %.0f statuses\n" .users .statuses}}'
-madonctl instance --stats --template "$TMPL" \
- --start "$(date +%s -d "$start")" \
- --end "$(date +%s -d "$end")"
--- a/examples/instance_statistics_evolution.sh Mon Mar 19 15:06:17 2018 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,28 +0,0 @@
-#! /bin/zsh
-#
-# Instance statistics for a given period (default: 4 last weeks)
-#
-# Usage: $0 [[--server INSTANCE] Number_of_weeks]
-#
-# Mikael
-
-if [[ $1 == "--server" || $1 == "-i" ]]; then
- opt=("--server" "$2")
- shift 2
-fi
-
-w=${1:-4}
-
-TMPL='({{(.date | fromunix).Format "2006-01-02"}}) {{.instance_name}}: {{printf "%.0f users, %.0f statuses\n" .users .statuses}}'
-
-typeset -i wa="$w"
-while (( wa >= 0 )); do
- when="$wa weeks ago"
- s=$(date +%s -d "$when")
- stats="$(madonctl instance ${opt[*]} --stats --template "$TMPL" \
- --start "$(( s-3600 ))" --end "$s" | tail -1)"
- if [[ -n $stats ]]; then
- echo "$when $stats"
- fi
- (( wa-=1 ))
-done