Skip to content

Commit

Permalink
Save to file
Browse files Browse the repository at this point in the history
  • Loading branch information
albertomn86 committed Dec 8, 2023
1 parent 1785b9a commit f09381c
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*.user
*.userosscache
*.sln.docstates
custom_TLE.txt

# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
Expand Down
1 change: 1 addition & 0 deletions TLEGenerator.Program/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class Config
public string NoradUrl { get; set; } = "https://celestrak.com/NORAD/elements/gp.php";
public List<string> Groups { get; set; } = [];
public string SatellitesListPath { get; set; } = "./satellites.json";
public string OutputFilePath { get; set; } = "./custom_TLE.txt";
public string TempFolder { get; set; } = "/tmp";
public int TempFilesDays { get; set; } = 1;

Expand Down
9 changes: 5 additions & 4 deletions TLEGenerator.Program/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ class Program
static void Main(string[] args)
{
Config config = new();
config.ReadConfigFile();
config.ReadConfigFile();

List<string> satellites = SatellitesReader.ReadList(config.SatellitesListPath);

TLEDataManager tleDataManager = new(config);
tleDataManager.RetrieveGroupsData();

StringBuilder tleFileContent = new();
int satellitesFound = 0;
using StreamWriter outputFile = new StreamWriter(config.OutputFilePath);

foreach (var satellite in satellites)
{
Expand All @@ -23,7 +24,7 @@ static void Main(string[] args)
if (tle != null) {
Console.WriteLine($"✓ Saved TLE for {tle.Title.Trim()} ({satellite})");
satellitesFound += 1;
tleFileContent.AppendLine(tle.ToString());
outputFile.WriteLine(tle.ToString());
continue;
}

Expand All @@ -32,6 +33,6 @@ static void Main(string[] args)

Console.WriteLine($"TLEs retrieved: {satellitesFound}/{satellites.Count}");
Console.WriteLine($"API requests: {tleDataManager.GetApiRequestsNumber()}");
Console.WriteLine(tleFileContent.ToString());
Console.WriteLine($"Output TLE file: {Path.GetFullPath(config.OutputFilePath)}");
}
}
1 change: 1 addition & 0 deletions TLEGenerator.Program/TLEGenerator.Program.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

<ItemGroup>
<Content Include="../config.json" CopyToOutputDirectory="Always" />
<Content Include="../satellites.json" CopyToOutputDirectory="Always" />
</ItemGroup>

</Project>
5 changes: 3 additions & 2 deletions TLEGenerator.Tests/TLEDataManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ public class TLEDataManagerTest
Config config = new()
{
NoradUrl = "fakeUrl",
Groups = ["weather"],
TempFolder = "TestData"
Groups = ["test"],
TempFolder = "TestData",
TempFilesDays = 65000
};

[TestMethod]
Expand Down
2 changes: 1 addition & 1 deletion TLEGenerator.Tests/TLEFileParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace TLEGenerator.Tests;
[TestClass]
public class TLEFileParserTests
{
const string TestFile = "./TestData/weather.txt";
const string TestFile = "./TestData/test.txt";

[TestMethod]
[DataRow("")]
Expand Down
File renamed without changes.
3 changes: 2 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"NoradUrl" : "https://celestrak.com/NORAD/elements/gp.php",
"Groups" : [ "weather" ],
"Groups" : [ "weather", "amateur" ],
"SatellitesListPath" : "./satellites.json",
"OutputFilePath" : "./custom_TLE.txt",
"TempFolder" : "/tmp",
"TempFilesDays" : 1
}

0 comments on commit f09381c

Please sign in to comment.