-
Notifications
You must be signed in to change notification settings - Fork 0
/
goes.go
69 lines (58 loc) · 1.59 KB
/
goes.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package cmd
import (
"fmt"
"os"
"github.com/quells/mastobot/internal/goes"
"github.com/quells/mastobot/internal/toot"
"github.com/spf13/cobra"
)
func init() {
goesCmd.PersistentFlags().StringVar(&instance, "instance", "", "Mastodon (or compatible) instance to interact with")
must(goesCmd.MarkPersistentFlagRequired("instance"))
goesCmd.AddCommand(goesWestCmd)
rootCmd.AddCommand(goesCmd)
}
var goesCmd = &cobra.Command{
Use: "goes",
Short: "Toot satellite image of Earth's hemisphere",
}
var goesWestCmd = &cobra.Command{
Use: "west",
Short: "Toot satellite image of Earth's western hemisphere from GOES-17",
RunE: func(cmd *cobra.Command, args []string) error {
const appName = "GOES-17"
_, err := toot.VerifyCredentials(cmd.Context(), instance, appName)
if err != nil {
return err
}
var large, thumbnail []byte
large, thumbnail, err = goes.GOES17(cmd.Context())
if err != nil {
return err
}
upload := toot.MediaUpload{
ContentType: toot.ContentTypeMediaJPEG,
File: large,
Thumbnail: thumbnail,
Description: "Satellite image of the western hemisphere of Earth",
Focus: [2]float64{0.5, 0.5},
}
var mediaID string
mediaID, err = upload.Submit(cmd.Context(), instance, appName)
if err != nil {
return err
}
_, _ = fmt.Fprintln(os.Stdout, mediaID)
status := toot.Status{
MediaIDs: []string{mediaID},
Visibility: toot.VisibilityPublic,
}
var statusID string
statusID, err = status.Submit(cmd.Context(), instance, appName)
if err != nil {
return err
}
_, _ = fmt.Fprintln(os.Stdout, statusID)
return nil
},
}