feat: organize code structure

This commit is contained in:
angelina-tsuboi
2023-05-07 08:32:56 -07:00
parent 890f896f91
commit 3d00a32555
3 changed files with 153 additions and 141 deletions

View File

@@ -2,7 +2,6 @@ package osint
import (
"fmt"
"bufio"
"os"
"github.com/TwiN/go-color"
"github.com/iskaa02/qalam/gradient"
@@ -160,146 +159,6 @@ func SatellitePositionVisualization() {
return
}
// TLE Parser Code
func TLEParser() {
options, _ := ioutil.ReadFile("txt/tle_parser.txt")
opt,_:=gradient.NewGradient("#1179ef", "cyan")
opt.Print("\n" + string(options))
var selection int = Option(0, 3)
if (selection == 1){
TLETextFile()
} else if (selection == 2) {
TLEPlainString()
}
return
}
func TLETextFile() {
fmt.Print("\n ENTER TEXT FILE PATH > ")
var path string
fmt.Scanln(&path)
file, err := os.Open(path)
if err != nil {
fmt.Println(color.Ize(color.Red, " [!] INVALID TEXT FILE"))
}
scanner := bufio.NewScanner(file)
scanner.Split(bufio.ScanLines)
var txtlines []string
var count int = 0
for scanner.Scan() {
txtlines = append(txtlines, scanner.Text())
count += 1
}
file.Close()
if (count < 2 || count > 3) {
fmt.Println(color.Ize(color.Red, " [!] INVALID TLE FORMAT"))
return
}
output := TLE{}
if (count == 3) {
var satelliteName string = txtlines[0]
output = ConstructTLE(satelliteName, txtlines[1], txtlines[2])
} else {
output = ConstructTLE("UNSPECIFIED", txtlines[0], txtlines[1])
}
PrintTLE(output)
}
func ConstructTLE(one string, two string, three string) TLE {
tle := TLE{}
tle.CommonName = one
firstArr := strings.Fields(two)
secondArr := strings.Fields(three)
tle.SatelliteCatalogNumber, _ = strconv.Atoi(firstArr[1][:len(firstArr[1])-1])
tle.ElsetClassificiation = string(firstArr[1][len(firstArr[1])-1])
tle.InternationalDesignator = firstArr[2]
tle.ElementSetEpoch, _ = strconv.ParseFloat(firstArr[3], 64)
tle.FirstDerivativeMeanMotion, _ = strconv.ParseFloat(firstArr[4], 64)
tle.SecondDerivativeMeanMotion = firstArr[5]
tle.BDragTerm = firstArr[6]
tle.ElementSetType, _ = strconv.Atoi(firstArr[7])
tle.ElementNumber, _ = strconv.Atoi(firstArr[8][:len(firstArr[8])-1])
tle.ChecksumOne, _ = strconv.Atoi(string(firstArr[8][len(firstArr[8])-1]))
tle.SatelliteCatalogNumber, _ = strconv.Atoi(secondArr[1])
tle.OrbitInclination, _ = strconv.ParseFloat(secondArr[2], 64)
tle.RightAscension, _ = strconv.ParseFloat(secondArr[3], 64)
tle.Eccentrcity, _ = strconv.ParseFloat("0." + secondArr[4], 64)
tle.Perigee, _ = strconv.ParseFloat(secondArr[5], 64)
tle.MeanAnamoly, _ = strconv.ParseFloat(secondArr[6], 64)
tle.MeanMotion, _ = strconv.ParseFloat(secondArr[7][:11], 64)
tle.RevolutionNumber, _ = strconv.Atoi(secondArr[7][11:16])
tle.ChecksumTwo, _ = strconv.Atoi(string(secondArr[7][len(secondArr[7])-1]))
return tle
}
func TLEPlainString(){
scanner := bufio.NewScanner(os.Stdin)
var lineOne string
var lineTwo string
var lineThree string
fmt.Print("\n ENTER LINE ONE (leave blank for unspecified name) > ")
scanner.Scan()
lineOne = scanner.Text()
fmt.Print("\n ENTER LINE TWO > ")
scanner.Scan()
lineTwo = scanner.Text()
fmt.Print("\n ENTER LINE THREE > ")
scanner.Scan()
lineThree = scanner.Text()
if (lineOne == "") {
lineOne = "UNSPECIFIED"
}
output := TLE{}
output = ConstructTLE(lineOne, lineTwo, lineThree)
PrintTLE(output)
}
// TODO: Right Ascension of Ascending Node (degrees)
func PrintTLE (tle TLE) {
fmt.Println(color.Ize(color.Purple, "\n╔═════════════════════════════════════════════════════════════╗"))
fmt.Println(color.Ize(color.Purple, GenRowString("Name", tle.CommonName)))
fmt.Println(color.Ize(color.Purple, GenRowString("Satellite Catalog Number", fmt.Sprintf("%d", tle.SatelliteCatalogNumber))))
fmt.Println(color.Ize(color.Purple, GenRowString("Elset Classification", tle.ElsetClassificiation)))
fmt.Println(color.Ize(color.Purple, GenRowString("International Designator", tle.InternationalDesignator)))
fmt.Println(color.Ize(color.Purple, GenRowString("Element Set Epoch (UTC)", fmt.Sprintf("%f", tle.ElementSetEpoch))))
fmt.Println(color.Ize(color.Purple, GenRowString("1st Derivative of the Mean Motion", fmt.Sprintf("%f", tle.FirstDerivativeMeanMotion))))
fmt.Println(color.Ize(color.Purple, GenRowString("2nd Derivative of the Mean Motion", tle.SecondDerivativeMeanMotion)))
fmt.Println(color.Ize(color.Purple, GenRowString("B* Drag Term", tle.BDragTerm)))
fmt.Println(color.Ize(color.Purple, GenRowString("Element Set Type", fmt.Sprintf("%d", tle.ElementSetType))))
fmt.Println(color.Ize(color.Purple, GenRowString("Element Number", fmt.Sprintf("%d", tle.ElementNumber))))
fmt.Println(color.Ize(color.Purple, GenRowString("Checksum Line One", fmt.Sprintf("%d", tle.ChecksumOne))))
fmt.Println(color.Ize(color.Purple, GenRowString("Orbit Inclination (degrees)", fmt.Sprintf("%f", tle.OrbitInclination))))
fmt.Println(color.Ize(color.Purple, GenRowString("Right Ascension of Ascending Node (degrees)", fmt.Sprintf("%f", tle.RightAscension))))
fmt.Println(color.Ize(color.Purple, GenRowString("Eccentricity", fmt.Sprintf("%f", tle.Eccentrcity))))
fmt.Println(color.Ize(color.Purple, GenRowString("Argument of Perigee (degrees)", fmt.Sprintf("%f", tle.Perigee))))
fmt.Println(color.Ize(color.Purple, GenRowString("Mean Anomaly (degrees)", fmt.Sprintf("%f", tle.MeanAnamoly))))
fmt.Println(color.Ize(color.Purple, GenRowString("Mean Motion (revolutions/day)", fmt.Sprintf("%f", tle.MeanMotion))))
fmt.Println(color.Ize(color.Purple, GenRowString("Revolution Number at Epoch", fmt.Sprintf("%d", tle.RevolutionNumber))))
fmt.Println(color.Ize(color.Purple, GenRowString("Checksum Line Two", fmt.Sprintf("%d", tle.ChecksumTwo))))
fmt.Println(color.Ize(color.Purple, "╚═════════════════════════════════════════════════════════════╝ \n\n"))
}
func GenRowString(intro string, input string) string{
var totalCount int = 4 + len(intro) + len(input) + 2
var useCount = 63 - totalCount

View File

@@ -1,5 +1,12 @@
package osint
import (
"fmt"
"github.com/TwiN/go-color"
"strconv"
"strings"
)
type TLE struct {
CommonName string
SatelliteCatalogNumber int
@@ -20,4 +27,57 @@ type TLE struct {
MeanMotion float64
RevolutionNumber int
ChecksumTwo int
}
func ConstructTLE(one string, two string, three string) TLE {
tle := TLE{}
tle.CommonName = one
firstArr := strings.Fields(two)
secondArr := strings.Fields(three)
tle.SatelliteCatalogNumber, _ = strconv.Atoi(firstArr[1][:len(firstArr[1])-1])
tle.ElsetClassificiation = string(firstArr[1][len(firstArr[1])-1])
tle.InternationalDesignator = firstArr[2]
tle.ElementSetEpoch, _ = strconv.ParseFloat(firstArr[3], 64)
tle.FirstDerivativeMeanMotion, _ = strconv.ParseFloat(firstArr[4], 64)
tle.SecondDerivativeMeanMotion = firstArr[5]
tle.BDragTerm = firstArr[6]
tle.ElementSetType, _ = strconv.Atoi(firstArr[7])
tle.ElementNumber, _ = strconv.Atoi(firstArr[8][:len(firstArr[8])-1])
tle.ChecksumOne, _ = strconv.Atoi(string(firstArr[8][len(firstArr[8])-1]))
tle.SatelliteCatalogNumber, _ = strconv.Atoi(secondArr[1])
tle.OrbitInclination, _ = strconv.ParseFloat(secondArr[2], 64)
tle.RightAscension, _ = strconv.ParseFloat(secondArr[3], 64)
tle.Eccentrcity, _ = strconv.ParseFloat("0." + secondArr[4], 64)
tle.Perigee, _ = strconv.ParseFloat(secondArr[5], 64)
tle.MeanAnamoly, _ = strconv.ParseFloat(secondArr[6], 64)
tle.MeanMotion, _ = strconv.ParseFloat(secondArr[7][:11], 64)
tle.RevolutionNumber, _ = strconv.Atoi(secondArr[7][11:16])
tle.ChecksumTwo, _ = strconv.Atoi(string(secondArr[7][len(secondArr[7])-1]))
return tle
}
func PrintTLE (tle TLE) {
fmt.Println(color.Ize(color.Purple, "\n╔═════════════════════════════════════════════════════════════╗"))
fmt.Println(color.Ize(color.Purple, GenRowString("Name", tle.CommonName)))
fmt.Println(color.Ize(color.Purple, GenRowString("Satellite Catalog Number", fmt.Sprintf("%d", tle.SatelliteCatalogNumber))))
fmt.Println(color.Ize(color.Purple, GenRowString("Elset Classification", tle.ElsetClassificiation)))
fmt.Println(color.Ize(color.Purple, GenRowString("International Designator", tle.InternationalDesignator)))
fmt.Println(color.Ize(color.Purple, GenRowString("Element Set Epoch (UTC)", fmt.Sprintf("%f", tle.ElementSetEpoch))))
fmt.Println(color.Ize(color.Purple, GenRowString("1st Derivative of the Mean Motion", fmt.Sprintf("%f", tle.FirstDerivativeMeanMotion))))
fmt.Println(color.Ize(color.Purple, GenRowString("2nd Derivative of the Mean Motion", tle.SecondDerivativeMeanMotion)))
fmt.Println(color.Ize(color.Purple, GenRowString("B* Drag Term", tle.BDragTerm)))
fmt.Println(color.Ize(color.Purple, GenRowString("Element Set Type", fmt.Sprintf("%d", tle.ElementSetType))))
fmt.Println(color.Ize(color.Purple, GenRowString("Element Number", fmt.Sprintf("%d", tle.ElementNumber))))
fmt.Println(color.Ize(color.Purple, GenRowString("Checksum Line One", fmt.Sprintf("%d", tle.ChecksumOne))))
fmt.Println(color.Ize(color.Purple, GenRowString("Orbit Inclination (degrees)", fmt.Sprintf("%f", tle.OrbitInclination))))
fmt.Println(color.Ize(color.Purple, GenRowString("Right Ascension of Ascending Node (degrees)", fmt.Sprintf("%f", tle.RightAscension))))
fmt.Println(color.Ize(color.Purple, GenRowString("Eccentricity", fmt.Sprintf("%f", tle.Eccentrcity))))
fmt.Println(color.Ize(color.Purple, GenRowString("Argument of Perigee (degrees)", fmt.Sprintf("%f", tle.Perigee))))
fmt.Println(color.Ize(color.Purple, GenRowString("Mean Anomaly (degrees)", fmt.Sprintf("%f", tle.MeanAnamoly))))
fmt.Println(color.Ize(color.Purple, GenRowString("Mean Motion (revolutions/day)", fmt.Sprintf("%f", tle.MeanMotion))))
fmt.Println(color.Ize(color.Purple, GenRowString("Revolution Number at Epoch", fmt.Sprintf("%d", tle.RevolutionNumber))))
fmt.Println(color.Ize(color.Purple, GenRowString("Checksum Line Two", fmt.Sprintf("%d", tle.ChecksumTwo))))
fmt.Println(color.Ize(color.Purple, "╚═════════════════════════════════════════════════════════════╝ \n\n"))
}

93
osint/tleparser.go Normal file
View File

@@ -0,0 +1,93 @@
package osint
import (
"fmt"
"os"
"github.com/TwiN/go-color"
"github.com/iskaa02/qalam/gradient"
"io/ioutil"
"bufio"
)
func TLEParser() {
options, _ := ioutil.ReadFile("txt/tle_parser.txt")
opt,_:=gradient.NewGradient("#1179ef", "cyan")
opt.Print("\n" + string(options))
var selection int = Option(0, 3)
if (selection == 1){
TLETextFile()
} else if (selection == 2) {
TLEPlainString()
}
return
}
func TLETextFile() {
fmt.Print("\n ENTER TEXT FILE PATH > ")
var path string
fmt.Scanln(&path)
file, err := os.Open(path)
if err != nil {
fmt.Println(color.Ize(color.Red, " [!] INVALID TEXT FILE"))
}
scanner := bufio.NewScanner(file)
scanner.Split(bufio.ScanLines)
var txtlines []string
var count int = 0
for scanner.Scan() {
txtlines = append(txtlines, scanner.Text())
count += 1
}
file.Close()
if (count < 2 || count > 3) {
fmt.Println(color.Ize(color.Red, " [!] INVALID TLE FORMAT"))
return
}
output := TLE{}
if (count == 3) {
var satelliteName string = txtlines[0]
output = ConstructTLE(satelliteName, txtlines[1], txtlines[2])
} else {
output = ConstructTLE("UNSPECIFIED", txtlines[0], txtlines[1])
}
PrintTLE(output)
}
func TLEPlainString(){
scanner := bufio.NewScanner(os.Stdin)
var lineOne string
var lineTwo string
var lineThree string
fmt.Print("\n ENTER LINE ONE (leave blank for unspecified name) > ")
scanner.Scan()
lineOne = scanner.Text()
fmt.Print("\n ENTER LINE TWO > ")
scanner.Scan()
lineTwo = scanner.Text()
fmt.Print("\n ENTER LINE THREE > ")
scanner.Scan()
lineThree = scanner.Text()
if (lineOne == "") {
lineOne = "UNSPECIFIED"
}
output := TLE{}
output = ConstructTLE(lineOne, lineTwo, lineThree)
PrintTLE(output)
}