Options to export schedule

This commit is contained in:
Tony Bark 2025-03-11 16:51:25 -04:00
parent 2d7cf1f6ca
commit c8dd778784
3 changed files with 48 additions and 2 deletions

3
.gitignore vendored
View file

@ -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/**
.idea/**
*.txt

View file

@ -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<TimeSpan>();
var storeSchedule = new List<String>();
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);
}

View file

@ -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.