Skip to content

Commit

Permalink
feat: mark space track data
Browse files Browse the repository at this point in the history
  • Loading branch information
Apoorva64 committed May 22, 2024
1 parent b96bdf1 commit 7ac4af7
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 79 deletions.
7 changes: 5 additions & 2 deletions celestrack/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ import (
)

func extractNoradIdFromTle(line2 string) string {
return strings.Split(line2, " ")[1]
// remove the 0 in the beginning
dirtyNorad := strings.Split(line2, " ")[1]
return strings.TrimLeft(dirtyNorad, "0")

}

func scrap() (map[string]spacetrack.TLE, error) {
func Scrap() (map[string]spacetrack.TLE, error) {
url := "https://celestrak.org/NORAD/elements/"
// Get the HTML
client := resty.New()
Expand Down
2 changes: 1 addition & 1 deletion celestrack/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

func Test_scrap(t *testing.T) {
m, err := scrap()
m, err := Scrap()
if err != nil {
return
}
Expand Down
159 changes: 84 additions & 75 deletions gen/go/proto/satellite/v1/satellite.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions gen/openapiv2/proto/satellite/v1/satellite.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,12 @@
},
"tleLine2": {
"type": "string"
},
"groups": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions proto/satellite/v1/satellite.proto
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ message SatelliteDetail {
string tle_line0 = 38;
string tle_line1 = 39;
string tle_line2 = 40;
repeated string groups = 41;
}

message GetSatellitePositionsRequest {
Expand Down
19 changes: 18 additions & 1 deletion service/satelliteservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/go-resty/resty/v2"
"github.com/joshuaferrara/go-satellite"
log "github.com/sirupsen/logrus"
"github.com/tsukoyachi/react-flight-tracker-satellite/celestrack"
"github.com/tsukoyachi/react-flight-tracker-satellite/gen/go/proto/satellite/v1"
"github.com/tsukoyachi/react-flight-tracker-satellite/spacetrack"
"google.golang.org/grpc/codes"
Expand Down Expand Up @@ -36,7 +37,6 @@ func NewSatelliteService() *SatelliteService {
if err != nil {
log.Error(err)
}
log.Println(len(data))

calculatedMap := make(map[string]spacetrack.TLE)
for _, tle := range data {
Expand All @@ -51,6 +51,22 @@ func NewSatelliteService() *SatelliteService {

}

// fetch from celestrak
celestrakData, err := celestrack.Scrap()
if err != nil {
log.Error(err)
}
for k, v := range celestrakData {
sat, ok := calculatedMap[k]
if !ok {
calculatedMap[k] = v
log.Info("Added ", k)
continue
}
sat.Group = append(sat.Group, v.Group...)
calculatedMap[k] = sat
}
log.Info("Total satellites: ", len(calculatedMap))
return &SatelliteService{
data: calculatedMap,
}
Expand Down Expand Up @@ -105,6 +121,7 @@ func (api SatelliteService) GetSatelliteDetail(ctx context.Context, req *v1.Sate
TleLine0: tle.TLE_LINE0,
TleLine1: tle.TLE_LINE1,
TleLine2: tle.TLE_LINE2,
Groups: tle.Group,
}, nil
}

Expand Down

0 comments on commit 7ac4af7

Please sign in to comment.