From a5a69b8f6242007bc3168aa26328662ad91c6efa Mon Sep 17 00:00:00 2001 From: angelina-tsuboi Date: Sat, 6 May 2023 18:14:08 -0700 Subject: [PATCH] feat: init Orbital Element Data for norad --- osint/osint.go | 106 ++++++++++++++++++++-------------------- osint/satellite.go | 6 --- txt/orbital_element.txt | 11 +++++ 3 files changed, 64 insertions(+), 59 deletions(-) create mode 100644 txt/orbital_element.txt diff --git a/osint/osint.go b/osint/osint.go index b00c93b..67a3bdf 100644 --- a/osint/osint.go +++ b/osint/osint.go @@ -40,59 +40,59 @@ type field string type orderBy string const authURL = "https://www.space-track.org/ajaxauth/login" const baseurl = "https://www.space-track.org/basicspacedata/query/class" -const epoch field = "EPOCH" -const tle field = "TLE" -const noradCatID field = "NORAD_CAT_ID" -const asc orderBy = "asc" -const desc orderBy = "desc" - -type operator string - -const dq operator = "" -const lt operator = "<" - -type SatcatResponse struct { - Result []struct { - InternationalDesignator string `json:"INTLDES"` - } `json:"Results"` -} - -type spacetrackArgs struct { - base string - class field - orderByField field - orderByDir orderBy - limit uint64 - filters filters -} - -type filters []filter -type filter struct { - filterType field - operator operator - value string -} - -func (f filters) render() string { - results := []string{} - for _, f := range f { - results = append(results, f.render()) - } - return strings.Join(results, "/") -} - -func (f filter) render() string { - return fmt.Sprint(f.filterType, "/", f.operator, f.value) -} - // Orbital Element Data Display Code func OrbitalElement() { - // NORAD ID or Catalog Display + options, _ := ioutil.ReadFile("txt/orbital_element.txt") + opt,_:=gradient.NewGradient("#1179ef", "cyan") + opt.Print("\n" + string(options)) + var selection int = Option(0, 3) + + if (selection == 1) { + vals := url.Values{} + vals.Add("identity", os.Getenv("SPACE_TRACK_USERNAME")) + vals.Add("password", os.Getenv("SPACE_TRACK_PASSWORD")) + vals.Add("query", "https://www.space-track.org/basicspacedata/query/class/satcat/orderby/SATNAME asc/limit/10/emptyresult/show") + + client := &http.Client{} + + resp, err := client.PostForm(authURL, vals) + if err != nil { + fmt.Println("0-") + } + + defer resp.Body.Close() + if resp.StatusCode < 200 || resp.StatusCode >= 300 { + fmt.Println("1-") + } + respData, err := ioutil.ReadAll(resp.Body) + + if err != nil { + fmt.Println("lols") + } + + var sats []Satellite + if err := json.Unmarshal(respData, &sats); err != nil { + fmt.Println("2-") + } + + fmt.Println(sats, len(sats)) + + } else if (selection == 2) { + fmt.Print("\n ENTER NORAD ID > ") + var norad string + fmt.Scanln(&norad) + PrintNORADInfo(norad) + } + + return +} + +func PrintNORADInfo(norad string) { vals := url.Values{} vals.Add("identity", os.Getenv("SPACE_TRACK_USERNAME")) vals.Add("password", os.Getenv("SPACE_TRACK_PASSWORD")) - vals.Add("query", "https://www.space-track.org/basicspacedata/query/class/satcat/orderby/SATNAME asc/limit/10/emptyresult/show") + vals.Add("query", "https://www.space-track.org/basicspacedata/query/class/gp_history/format/tle/NORAD_CAT_ID/" + norad + "/orderby/EPOCH%20desc/limit/1") client := &http.Client{} @@ -111,12 +111,12 @@ func OrbitalElement() { fmt.Println("lols") } - var sats []Satellite - if err := json.Unmarshal(respData, &sats); err != nil { - fmt.Println("2-") - } - - fmt.Println(sats, len(sats)) + tleLines := strings.Fields(string(respData)) + mid := (len(tleLines)/2) + 1 + lineOne := strings.Join(tleLines[:mid], " ") + lineTwo := strings.Join(tleLines[mid:], " ") + tle := ConstructTLE("UNSPECIFIED", lineOne, lineTwo) + PrintTLE(tle) } // TLE Parser Code diff --git a/osint/satellite.go b/osint/satellite.go index 0fe74aa..27ed073 100644 --- a/osint/satellite.go +++ b/osint/satellite.go @@ -1,6 +1,5 @@ package osint -// Struct for holding satellite information during and before propagation type Satellite struct { INTLDES string `json:"INTLDES"` NORAD_CAT_ID string `json:"NORAD_CAT_ID"` @@ -27,8 +26,3 @@ type Satellite struct { OBJECT_ID string `json:"OBJECT_ID"` OBJECT_NUMBER string `json:"OBJECT_NUMBER"` } - - -type GravConst struct { - mu, radiusearthkm, xke, tumin, j2, j3, j4, j3oj2 float64 -} \ No newline at end of file diff --git a/txt/orbital_element.txt b/txt/orbital_element.txt new file mode 100644 index 0000000..f14369d --- /dev/null +++ b/txt/orbital_element.txt @@ -0,0 +1,11 @@ + + + [ 1 ] Select from Satellite Catalog + + [ 2 ] Input NORAD Catalog ID + + [ 3 ] Back to Main Menu + + [ 0 ] Exit SatIntel + +================================================================================================================================= \ No newline at end of file