mirror of
https://github.com/tonytins/PublishTimes.git
synced 2025-03-15 04:01:20 +00:00
Compare commits
No commits in common. "8cf1e917f6cbeb848cf4b0c2961e93593a38ab65" and "46a86f9ef8eab0412c73c77305dcadcbe27236bd" have entirely different histories.
8cf1e917f6
...
46a86f9ef8
3 changed files with 7 additions and 21 deletions
|
@ -1,3 +1,2 @@
|
|||
global using Tomlyn;
|
||||
global using Tomlyn.Model;
|
||||
global using System.Globalization;
|
||||
global using System.Diagnostics;
|
||||
|
|
24
Program.cs
24
Program.cs
|
@ -3,21 +3,20 @@ const string banner = "=== Publish Times ===";
|
|||
|
||||
var numberOfArticles = 5; // Define how many articles to schedule
|
||||
var startTime = new TimeSpan(9, 0, 0); // Starting time at 9:00 AM
|
||||
var rng = new Random();
|
||||
var random = new Random();
|
||||
var scheduledTimes = new List<TimeSpan>();
|
||||
var storeSchedule = new List<String>();
|
||||
// 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 communities = new[] { "Games", "Politics", "Research", "Technology" };
|
||||
var scheduleFile = "schedule.txt";
|
||||
var cfgFile = "config.toml";
|
||||
|
||||
for (int i = 0; i < numberOfArticles; i++)
|
||||
{
|
||||
var baseDelayHours = rng.Next(2, 4); // Randomly choose between 2-3 hours delay
|
||||
var minutesToAdd = rng.Next(0, 60); // Randomly choose minutes (0-59)
|
||||
var baseDelayHours = random.Next(2, 4); // Randomly choose between 2-3 hours delay
|
||||
var minutesToAdd = random.Next(0, 60); // Randomly choose minutes (0-59)
|
||||
|
||||
// Calculate new time by adding base delay and random minutes
|
||||
var nextTime = startTime.Add(new TimeSpan(baseDelayHours, minutesToAdd, 0));
|
||||
|
@ -63,10 +62,6 @@ if (Console.ReadKey().Key == ConsoleKey.Y)
|
|||
var cfgPath = Path.Combine(appDir, cfgFile);
|
||||
var filePath = Path.Combine(fileDir, scheduleFile);
|
||||
var appendSchedule = false;
|
||||
var topic = "";
|
||||
|
||||
var chooseTopic = rng.Next(0, communities.Length);
|
||||
topic = communities[chooseTopic];
|
||||
|
||||
// If the config file exists, read from that but don't assume anything is filled
|
||||
if (File.Exists(cfgPath))
|
||||
|
@ -75,8 +70,6 @@ if (Console.ReadKey().Key == ConsoleKey.Y)
|
|||
var model = Toml.ToModel(toml);
|
||||
var usrDir = (string)model["path"];
|
||||
var usrFileName = (string)model["file"];
|
||||
var tomlList = string.Join(", ", (TomlArray)model["topics"]);
|
||||
var usrList = tomlList.Split(',');
|
||||
|
||||
if (!string.IsNullOrEmpty(usrDir))
|
||||
fileDir = usrDir;
|
||||
|
@ -84,13 +77,6 @@ if (Console.ReadKey().Key == ConsoleKey.Y)
|
|||
if (!string.IsNullOrEmpty(usrFileName))
|
||||
scheduleFile = usrFileName;
|
||||
|
||||
if (usrList.Length > 0)
|
||||
{
|
||||
var chooseUsrTopic = rng.Next(0, usrList.Length);
|
||||
topic = usrList[chooseUsrTopic];
|
||||
}
|
||||
|
||||
|
||||
// Set new file Path
|
||||
filePath = Path.Combine(fileDir, scheduleFile);
|
||||
}
|
||||
|
@ -106,8 +92,10 @@ if (Console.ReadKey().Key == ConsoleKey.Y)
|
|||
// Write to file.
|
||||
using (var outputFile = new StreamWriter(filePath, appendSchedule))
|
||||
{
|
||||
// Add separator between times
|
||||
if (appendSchedule)
|
||||
outputFile.WriteLine(" ---");
|
||||
|
||||
outputFile.WriteLine($" === {topic} ===");
|
||||
foreach (var line in storeSchedule)
|
||||
outputFile.WriteLine(line);
|
||||
}
|
||||
|
|
|
@ -1,3 +1,2 @@
|
|||
path = "/home/tonytins/Documents/"
|
||||
file = "newscycle.txt"
|
||||
topics = [ "Games", "Technology", "Cybersecurity" ]
|
||||
|
|
Loading…
Add table
Reference in a new issue