diff --git a/.gitignore b/.gitignore index 233762f..6136cef 100644 --- a/.gitignore +++ b/.gitignore @@ -545,3 +545,4 @@ FodyWeavers.xsd .idea/** *.txt +*.toml diff --git a/GlobalUsings.cs b/GlobalUsings.cs new file mode 100644 index 0000000..8324182 --- /dev/null +++ b/GlobalUsings.cs @@ -0,0 +1,2 @@ +global using Tomlyn; +global using System.Diagnostics; diff --git a/Program.cs b/Program.cs index de15230..b4b0f6c 100644 --- a/Program.cs +++ b/Program.cs @@ -6,6 +6,12 @@ var startTime = new TimeSpan(9, 0, 0); // Starting time at 9:00 AM var random = new Random(); var scheduledTimes = new List(); var storeSchedule = new List(); +// App directory is used for config file +var appDir = Directory.GetCurrentDirectory(); +// File directory is used for file location set in config +var fileDir = Directory.GetCurrentDirectory(); +var scheduleFile = "schedule.txt"; +var cfgFile = "config.toml"; for (int i = 0; i < numberOfArticles; i++) { @@ -53,11 +59,28 @@ Console.WriteLine("Export? Y/N"); if (Console.ReadKey().Key == ConsoleKey.Y) { - var appPath = Directory.GetCurrentDirectory(); - var scheduleFile = "schedule.txt"; - var filePath = Path.Combine(appPath, scheduleFile); + var cfgPath = Path.Combine(appDir, cfgFile); + var filePath = Path.Combine(fileDir, scheduleFile); var appendSchedule = false; + // If the config file exists, read from that but don't assume anything is filled + if (File.Exists(cfgPath)) + { + var toml = File.ReadAllText(cfgPath); + var model = Toml.ToModel(toml); + var usrDir = (string)model["path"]; + var usrFileName = (string)model["file"]; + + if (!string.IsNullOrEmpty(usrDir)) + fileDir = usrDir; + + if (!string.IsNullOrEmpty(usrFileName)) + scheduleFile = usrFileName; + + // Set new file Path + filePath = Path.Combine(fileDir, scheduleFile); + } + // If the file already exists, assume a previous schedule was written if (File.Exists(filePath)) { @@ -67,7 +90,7 @@ if (Console.ReadKey().Key == ConsoleKey.Y) } // Write to file. - using (var outputFile = new StreamWriter(Path.Combine(appPath, scheduleFile), appendSchedule)) + using (var outputFile = new StreamWriter(filePath, appendSchedule)) { // Add separator between times if (appendSchedule) @@ -76,11 +99,7 @@ if (Console.ReadKey().Key == ConsoleKey.Y) foreach (var line in storeSchedule) outputFile.WriteLine(line); } +} - // Clear list from memory before exit - storeSchedule.Clear(); -} -else -{ - Environment.Exit(Environment.ExitCode); -} +// Clear list from memory before exit +storeSchedule.Clear(); diff --git a/PublishTimes.csproj b/PublishTimes.csproj index fd4bd08..109581c 100644 --- a/PublishTimes.csproj +++ b/PublishTimes.csproj @@ -7,4 +7,8 @@ enable + + + + diff --git a/README.md b/README.md index ed804da..98d5dd7 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ This is a very simple console application that generates a list of times to sche ## Background -A while back, I [found a tool](https://schedule.lemmings.world) to schedule articles on Lemmy. I've been posting within a few hour apart at random minutes and I wanted to something decide that for me. I had AI write the algorithm. +A while back, I [found a tool](https://schedule.lemmings.world) to schedule articles on Lemmy. I've been posting within a few hour apart at random minutes and I wanted to something decide that for me. I had AI write the base algorithm everything else is my own touches. ## License diff --git a/config.toml.sample b/config.toml.sample new file mode 100644 index 0000000..c49564a --- /dev/null +++ b/config.toml.sample @@ -0,0 +1,2 @@ +path = "/home/tonytins/Documents/" +file = "newscycle.txt"