-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisualPass.go
More file actions
75 lines (67 loc) · 1.85 KB
/
visualPass.go
File metadata and controls
75 lines (67 loc) · 1.85 KB
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
70
71
72
73
74
75
package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
"net/url"
"time"
)
type visual struct {
Info struct {
Satname string `json:"satname"`
}
Pass []getPass `json:"passes"`
}
type getPass struct {
StartAz float64 `json:"maxAz"`
StartAzComp string `json:"maxAzCompass"`
StartUTC int `json:"maxUTC"`
EndUTC int `json:"endUTC"`
StartEl float64 `json:"maxEl"`
EndAz float64 `json:"endAz"`
EndAzComp string `json:"endAzCompass"`
Mag float32 `json:"mag"`
}
func visualPass() {
var id int
fmt.Println("Enter NORAD ID: ")
fmt.Scan(&id)
apiKey := setKey()
encoded := url.QueryEscape(apiKey)
url := fmt.Sprintf("https://api.n2yo.com/rest/v1/satellite/visualpasses/%d/41.702/-76.014/100/2/300/&apiKey=%s", id, encoded)
resp, err := http.Get(url)
if err != nil {
log.Fatal("Error requesting Sat data:", err)
}
resp.Close = true
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
log.Fatalf("Unexpected response status: %s", resp.Status)
}
var passInfo visual
err = json.NewDecoder(resp.Body).Decode(&passInfo)
if err != nil {
log.Fatal("Error parsing JSON:", err)
}
fmt.Println("Satellite Name:", passInfo.Info.Satname)
fmt.Println()
if len(passInfo.Pass) == 0 {
fmt.Println("Satellite not visible from your location for next 2 days.")
}
for _, i := range passInfo.Pass {
fmt.Println("Starting Azimuth of Pass (degrees):", i.StartAz)
fmt.Println("Direction:", i.StartAzComp)
fmt.Println("Elevation (degrees):", i.StartEl)
fmt.Println(time.Unix(int64(i.StartUTC), 0))
fmt.Println()
fmt.Println("Ending Azimuth of Pass (degrees):", i.EndAz)
fmt.Println("Direction at End of Pass:", i.EndAzComp)
fmt.Println(time.Unix(int64(i.EndUTC), 0))
if i.Mag == 100000 {
fmt.Println("Magnitude cannot be determined.")
} else {
fmt.Println("Apparent Magnitude:", i.Mag)
}
}
}