Skip to content

Commit c4d0bf2

Browse files
committed
β›„οΈπŸΈ ↝ Docking locations are now an available entity to query from
1 parent 999121b commit c4d0bf2

File tree

10 files changed

+292
-116
lines changed

10 files changed

+292
-116
lines changed
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
package main
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"io"
7+
"net/http"
8+
"time"
9+
)
10+
11+
type DockingLocationResponse struct {
12+
Count int `json:"count"`
13+
Results []DockingLocation `json:"results"`
14+
}
15+
16+
type DockingLocation struct {
17+
ID int `json:"id"`
18+
Name string `json:"name"`
19+
SpaceStation SpaceStation `json:"spacestation"`
20+
Spacecraft *Spacecraft `json:"spacecraft"`
21+
Payload *Payload `json:"payload"`
22+
}
23+
24+
type SpaceStation struct {
25+
ID int `json:"id"`
26+
Name string `json:"name"`
27+
URL string `json:"url"`
28+
Image ImageDetail `json:"image"`
29+
}
30+
31+
type Spacecraft struct {
32+
ID int `json:"id"`
33+
Name string `json:"name"`
34+
URL string `json:"url"`
35+
}
36+
37+
type Payload struct {
38+
ID int `json:"id"`
39+
Name string `json:"name"`
40+
}
41+
42+
type ImageDetail struct {
43+
ID int `json:"id"`
44+
Name string `json:"name"`
45+
ImageURL string `json:"image_url"`
46+
ThumbnailURL string `json:"thumbnail_url"`
47+
Credit string `json:"credit"`
48+
License License `json:"license"`
49+
SingleUse bool `json:"single_use"`
50+
}
51+
52+
type License struct {
53+
ID int `json:"id"`
54+
Name string `json:"name"`
55+
Priority int `json:"priority"`
56+
Link string `json:"link"`
57+
}
58+
59+
func main() {
60+
fmt.Println("πŸ›°οΈ Fetching most recent docking location...")
61+
62+
url := "https://ll.thespacedevs.com/2.3.0/config/docking_locations/?limit=1&format=json"
63+
client := &http.Client{Timeout: 10 * time.Second}
64+
65+
resp, err := client.Get(url)
66+
if err != nil {
67+
fmt.Printf("❌ Request error: %v\n", err)
68+
return
69+
}
70+
defer resp.Body.Close()
71+
72+
if resp.StatusCode != http.StatusOK {
73+
fmt.Printf("❌ Unexpected response code: %d\n", resp.StatusCode)
74+
return
75+
}
76+
77+
body, err := io.ReadAll(resp.Body)
78+
if err != nil {
79+
fmt.Printf("❌ Failed to read body: %v\n", err)
80+
return
81+
}
82+
83+
var data DockingLocationResponse
84+
if err := json.Unmarshal(body, &data); err != nil {
85+
fmt.Printf("❌ JSON error: %v\n", err)
86+
return
87+
}
88+
89+
if len(data.Results) == 0 {
90+
fmt.Println("⚠️ No docking locations found.")
91+
return
92+
}
93+
94+
loc := data.Results[0]
95+
fmt.Println("βœ… Most Recent Docking Location:")
96+
fmt.Printf("- Name: %s\n", loc.Name)
97+
fmt.Printf("- Station: %s\n", loc.SpaceStation.Name)
98+
fmt.Printf(" β€’ Image: %s\n", loc.SpaceStation.Image.ImageURL)
99+
fmt.Printf(" β€’ Credit: %s\n", loc.SpaceStation.Image.Credit)
100+
fmt.Printf(" β€’ License: %s (%s)\n", loc.SpaceStation.Image.License.Name, loc.SpaceStation.Image.License.Link)
101+
102+
if loc.Spacecraft != nil {
103+
fmt.Printf("- Spacecraft: %s\n", loc.Spacecraft.Name)
104+
} else {
105+
fmt.Println("- Spacecraft: None")
106+
}
107+
108+
if loc.Payload != nil {
109+
fmt.Printf("- Payload: %s\n", loc.Payload.Name)
110+
} else {
111+
fmt.Println("- Payload: None")
112+
}
113+
}

β€Žbackend/cmd/simple-sync-programs.goβ€Ž

Lines changed: 0 additions & 116 deletions
This file was deleted.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package main
2+
3+
import (
4+
"log"
5+
"os"
6+
7+
"github.com/signal-k/notifs/internal/sync"
8+
)
9+
10+
func main() {
11+
if err := sync.SyncMostRecentDockingLocation(); err != nil {
12+
log.Printf("❌ Docking location sync failed: %v", err)
13+
os.Exit(1)
14+
}
15+
log.Println("βœ… Docking location sync completed successfully.")
16+
}

0 commit comments

Comments
Β (0)