From 24ac4e797dfa215786fb4cbc1852c5cd77a72a7e Mon Sep 17 00:00:00 2001 From: angelina-tsuboi Date: Sun, 7 May 2023 16:32:42 -0700 Subject: [PATCH] feat: visual passes --- cli/cli.go | 2 +- go.mod | 2 ++ go.sum | 6 ++++ osint/orbitalprediction.go | 58 ++++++++++++++++++++++---------------- 4 files changed, 43 insertions(+), 25 deletions(-) diff --git a/cli/cli.go b/cli/cli.go index 74fe168..bca8919 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -41,7 +41,7 @@ func DisplayFunctions(x int) { Banner() Option() } else if (x == 3) { - osint.SatellitePositionVisualization() + osint.OrbitalPrediction() Banner() Option() }else if (x == 4) { diff --git a/go.mod b/go.mod index e90c9db..1968db2 100644 --- a/go.mod +++ b/go.mod @@ -9,6 +9,7 @@ require ( github.com/hashicorp/hcl v1.0.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/iskaa02/qalam v0.3.0 // indirect + github.com/joshuaferrara/go-satellite v0.0.0-20220611180459-512638c64e5b // indirect github.com/lucasb-eyer/go-colorful v1.0.3 // indirect github.com/magiconair/properties v1.8.7 // indirect github.com/manifoldco/promptui v0.9.0 // indirect @@ -18,6 +19,7 @@ require ( github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/olekukonko/tablewriter v0.0.5 // indirect github.com/pelletier/go-toml/v2 v2.0.6 // indirect + github.com/pkg/errors v0.9.1 // indirect github.com/spf13/afero v1.9.3 // indirect github.com/spf13/cast v1.5.0 // indirect github.com/spf13/cobra v1.7.0 // indirect diff --git a/go.sum b/go.sum index 23e004c..68bf547 100644 --- a/go.sum +++ b/go.sum @@ -127,6 +127,8 @@ github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2 github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/iskaa02/qalam v0.3.0 h1:yA7+MXkXbkP0HRDpkODC3bgQG0e5mjsYOsawwYP2v5k= github.com/iskaa02/qalam v0.3.0/go.mod h1:BRa4ht8cMjl27tNzhtuach90dBTma5seOzjpMGA5MY4= +github.com/joshuaferrara/go-satellite v0.0.0-20220611180459-512638c64e5b h1:JlltDRgni6FuoFwluvoZCrE6cmpojccO4WsqeYlFJLE= +github.com/joshuaferrara/go-satellite v0.0.0-20220611180459-512638c64e5b/go.mod h1:msW2QeN9IsnRyvuK8OBAzBwn6DHwXpiAiqBk8dbLfrU= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= @@ -150,8 +152,11 @@ github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyua github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= +github.com/onsi/ginkgo v1.2.1-0.20160509182050-5437a97bf824/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/gomega v0.0.0-20160516222431-c73e51675ad2/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= github.com/pelletier/go-toml/v2 v2.0.6 h1:nrzqCb7j9cDFj2coyLNLaZuJTLjWjlaz6nvTvIwycIU= github.com/pelletier/go-toml/v2 v2.0.6/go.mod h1:eumQOmlWiOPt5WriQQqoM5y18pDHwha2N+QD+EUNTek= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= @@ -476,6 +481,7 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/yaml.v2 v2.0.0-20160301204022-a83829b6f129/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/osint/orbitalprediction.go b/osint/orbitalprediction.go index 67471db..e456f67 100644 --- a/osint/orbitalprediction.go +++ b/osint/orbitalprediction.go @@ -4,7 +4,12 @@ import ( "fmt" "github.com/iskaa02/qalam/gradient" "io/ioutil" - "github.com/joshuaferrara/go-satellite" + // "github.com/joshuaferrara/go-satellite" + "strconv" + "os" + "github.com/TwiN/go-color" + "net/http" + "encoding/json" ) func OrbitalPrediction() { @@ -12,9 +17,9 @@ func OrbitalPrediction() { opt,_:=gradient.NewGradient("#1179ef", "cyan") opt.Print("\n" + string(options)) var selection int = Option(0, 4) - + if (selection == 1) { - + GetVisualPrediction() } else if (selection == 2) { } else if (selection == 3) { @@ -24,9 +29,9 @@ func OrbitalPrediction() { return } -func GetVisualPrediction(norad string) { +func GetVisualPrediction() { selection := SatelliteSelection() - if selection == nil { + if selection.norad == "" { fmt.Println(color.Ize(color.Red, " [!] ERROR: INVALID INPUT")) return } @@ -48,7 +53,7 @@ func GetVisualPrediction(norad string) { _, err := strconv.ParseFloat(latitude, 64) _, err2 := strconv.ParseFloat(longitude, 64) - _, err3 := strconv.ParseFloat(altitude) + _, err3 := strconv.ParseFloat(altitude, 64) _, err4 := strconv.Atoi(days) _, err5:= strconv.Atoi(vis) @@ -57,7 +62,7 @@ func GetVisualPrediction(norad string) { return } - url := "https://api.n2yo.com/rest/v1/satellite/visualpasses/" + norad + "/" + latitude + "/" + longitude + "/" + altitude + "/" + days + "/" + vis + "/&apiKey=" + os.Getenv("N2YO_API_KEY") + url := "https://api.n2yo.com/rest/v1/satellite/visualpasses/" + selection.norad + "/" + latitude + "/" + longitude + "/" + altitude + "/" + days + "/" + vis + "/&apiKey=" + os.Getenv("N2YO_API_KEY") resp, err := http.Get(url) if err != nil { fmt.Println(err) @@ -74,19 +79,24 @@ func GetVisualPrediction(norad string) { fmt.Println(color.Ize(color.Purple, "║ Satellite Information ║")) fmt.Println(color.Ize(color.Purple, "╠═════════════════════════════════════════════════════════════╣")) - fmt.Println(color.Ize(color.Purple, GenRowString("Satellite Name", data.Info.Satname))) - fmt.Println(color.Ize(color.Purple, GenRowString("Satellite ID", fmt.Sprintf("%d", data.Info.Satid)))) + fmt.Println(color.Ize(color.Purple, GenRowString("Satellite Name", data.Info.SatName))) + fmt.Println(color.Ize(color.Purple, GenRowString("Satellite ID", fmt.Sprintf("%d", data.Info.SatID)))) fmt.Println(color.Ize(color.Purple, GenRowString("Transactions Count", fmt.Sprintf("%d", data.Info.TransactionsCount)))) fmt.Println(color.Ize(color.Purple, GenRowString("Passes Count", fmt.Sprintf("%d", data.Info.PassesCount)))) - fmt.Println(color.Ize(color.Purple, "╠═════════════════════════════════════════════════════════════╣")) - fmt.Println(color.Ize(color.Purple, "║ Satellite Passes ║")) - fmt.Println(color.Ize(color.Purple, "╠═════════════════════════════════════════════════════════════╣")) - - for in, pos := range data.Passes { - PrintVisualPass(pos, in == len(data.Passes) - 1) - } + if (len(data.Passes) > 0) { + fmt.Println(color.Ize(color.Purple, "╠═════════════════════════════════════════════════════════════╣")) + fmt.Println(color.Ize(color.Purple, "║ Satellite Passes ║")) + fmt.Println(color.Ize(color.Purple, "╠═════════════════════════════════════════════════════════════╣")) + + for in, pos := range data.Passes { + PrintVisualPass(pos, in == len(data.Passes) - 1) + } + } else { + fmt.Println(color.Ize(color.Purple, "╚═════════════════════════════════════════════════════════════╝\n\n")) + } + return } func GetRadioPrediction() { @@ -97,7 +107,7 @@ func GetSGP4Prediction() { } -func SatelliteSelection() SatelliteSelection { +func SatelliteSelection() SatelliteSelectionType { options, _ := ioutil.ReadFile("txt/orbital_element.txt") opt,_:=gradient.NewGradient("#1179ef", "cyan") opt.Print("\n" + string(options)) @@ -106,22 +116,22 @@ func SatelliteSelection() SatelliteSelection { result := SelectSatellite() if (result == "") { - return + return SatelliteSelectionType{} } - return SatelliteSelection{norad: extractNorad(result), name: result} + return SatelliteSelectionType{norad: extractNorad(result), name: result} } else if (selection == 2) { fmt.Print("\n ENTER NORAD ID > ") var norad string fmt.Scanln(&norad) - return SatelliteSelection{norad: norad, name: "UNSPECIFIED"} + return SatelliteSelectionType{norad: norad, name: "UNSPECIFIED"} } - return nil + return SatelliteSelectionType{} } -type SatelliteSelection struct { +type SatelliteSelectionType struct { norad string name string } @@ -153,14 +163,14 @@ type Pass struct { Duration int `json:"duration"` } -func PrintVisualPass (pass Pass) { +func PrintVisualPass (pass Pass, last bool) { fmt.Println(color.Ize(color.Purple, GenRowString("Start Azimuth", fmt.Sprintf("%f", pass.StartAz)))) fmt.Println(color.Ize(color.Purple, GenRowString("Start Azimuth Compass", pass.StartAzCompass))) fmt.Println(color.Ize(color.Purple, GenRowString("Start Elevation", fmt.Sprintf("%f", pass.StartEl)))) fmt.Println(color.Ize(color.Purple, GenRowString("Start UTC", fmt.Sprintf("%d", pass.StartUTC)))) fmt.Println(color.Ize(color.Purple, GenRowString("Azimuth for Max Elevation", fmt.Sprintf("%f", pass.MaxAz)))) fmt.Println(color.Ize(color.Purple, GenRowString("Azimuth Compass for Max Elevation", pass.MaxAzCompass))) - fmt.Println(color.Ize(color.Purple, GenRowString("Max Elevation", fmt.Sprintf("%d", pass.MaxEl)))) + fmt.Println(color.Ize(color.Purple, GenRowString("Max Elevation", fmt.Sprintf("%f", pass.MaxEl)))) fmt.Println(color.Ize(color.Purple, GenRowString("Max UTC", fmt.Sprintf("%d", pass.MaxUTC)))) fmt.Println(color.Ize(color.Purple, GenRowString("End Azimuth", fmt.Sprintf("%f", pass.EndAz)))) fmt.Println(color.Ize(color.Purple, GenRowString("End Azimuth Compass", pass.EndAzCompass)))