From c8dd77878437c111d1bf2cf386ae62d05a526436 Mon Sep 17 00:00:00 2001 From: Tony Bark Date: Tue, 11 Mar 2025 16:51:25 -0400 Subject: [PATCH] Options to export schedule --- .gitignore | 3 ++- Program.cs | 43 ++++++++++++++++++++++++++++++++++++++++++- README.md | 4 ++++ 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index d30a9c2..233762f 100644 --- a/.gitignore +++ b/.gitignore @@ -543,4 +543,5 @@ FodyWeavers.xsd # Custom rules (everything added below won't be overriden by 'Generate .gitignore File' if you use 'Update' option) -.idea/** \ No newline at end of file +.idea/** +*.txt diff --git a/Program.cs b/Program.cs index d7ba8a6..ce1a0c9 100644 --- a/Program.cs +++ b/Program.cs @@ -5,6 +5,7 @@ var numberOfArticles = 5; // Define how many articles to schedule 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(); for (int i = 0; i < numberOfArticles; i++) { @@ -40,6 +41,46 @@ string TimeSpanToAMPM(TimeSpan time) Console.WriteLine(banner); foreach (var time in scheduledTimes) { + var articleTime = $"Article {scheduledTimes.IndexOf(time) + 1} Scheduled at: {TimeSpanToAMPM(time)}"; // Correct format string to display time in 12-hour format with AM/PM - Console.WriteLine($"Article {scheduledTimes.IndexOf(time) + 1} Scheduled at: {TimeSpanToAMPM(time)}"); + Console.WriteLine(articleTime); + // Store the schedule to memory for option export + storeSchedule.Add(articleTime); +} + +// Give the user an option to export the schedule +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 appendSchedule = false; + + // If the file already exists, assume the schedule was written + if (File.Exists(filePath)) + { + Console.WriteLine($"{Environment.NewLine}Add another schedule? Y/N"); + if (Console.ReadKey().Key == ConsoleKey.Y) + appendSchedule = true; + } + + // Write to file. + using (var outputFile = new StreamWriter(Path.Combine(appPath, scheduleFile), appendSchedule)) + { + // Add separator between times + if (appendSchedule) + outputFile.WriteLine(" ---"); + + foreach (var line in storeSchedule) + outputFile.WriteLine(line); + } + + // Clear list and start over + storeSchedule.Clear(); +} +else +{ + Environment.Exit(Environment.ExitCode); } diff --git a/README.md b/README.md index 1044fec..ed804da 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,10 @@ This is a very simple console application that generates a list of times to schedule news with a 2-3 hour delay and a 30 minute time gap per-article. +## 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. + ## License I hereby waive this project under the public domain - see [UNLICENSE](UNLICENSE) for details.