less editorializing
This commit is contained in:
parent
9f99566413
commit
4fc8ef9a29
145
Program.cs
145
Program.cs
@ -9,6 +9,7 @@ using franz;
|
|||||||
using Ical.Net;
|
using Ical.Net;
|
||||||
using Ical.Net.CalendarComponents;
|
using Ical.Net.CalendarComponents;
|
||||||
using Ical.Net.DataTypes;
|
using Ical.Net.DataTypes;
|
||||||
|
using Ical.Net.Serialization;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace director
|
namespace director
|
||||||
@ -21,7 +22,9 @@ namespace director
|
|||||||
private static Scratch scratch;
|
private static Scratch scratch;
|
||||||
private static HttpClient httpClient;
|
private static HttpClient httpClient;
|
||||||
private static DateTime searchStart = DateTime.Now; //is it slower to just call datetime.now every time? /shrug
|
private static DateTime searchStart = DateTime.Now; //is it slower to just call datetime.now every time? /shrug
|
||||||
private static DateTime searchEnd = DateTime.Now.AddDays(14);
|
private static DateTime searchEnd = DateTime.Now.AddDays(7);
|
||||||
|
//I don't understand why the entire .net ecosystem insists on ignoring ToString(). Is it really that much fun writing a serializer factory? ...java programmers.
|
||||||
|
private static EventSerializer ser = new EventSerializer();
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
if (!File.Exists("appsettings.json"))
|
if (!File.Exists("appsettings.json"))
|
||||||
@ -48,133 +51,69 @@ namespace director
|
|||||||
}
|
}
|
||||||
private static async Task calendarCheck()
|
private static async Task calendarCheck()
|
||||||
{
|
{
|
||||||
//pull calendar ics's
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
lock (scratch)
|
||||||
|
{
|
||||||
|
scratch.agenda.Clear();
|
||||||
|
}
|
||||||
Task.WaitAll(
|
Task.WaitAll(
|
||||||
checkYoutube(),
|
checkCalendar(conf.calendar_twitch, "youtube", (ref Schedulable.Schedulable n) =>
|
||||||
checkTwitch()
|
{
|
||||||
|
n.ScedulableType = Schedulable.ScedulableType.YTRelease;
|
||||||
|
}),
|
||||||
|
checkCalendar(conf.calendar_twitch, "twitch", (ref Schedulable.Schedulable n) =>
|
||||||
|
{
|
||||||
|
n.ScedulableType = Schedulable.ScedulableType.TwitchStream;
|
||||||
|
})
|
||||||
);
|
);
|
||||||
//await checkTwitch();
|
lock (scratch)
|
||||||
|
{
|
||||||
|
scratch.Save();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Console.Error.WriteLine("sure would be nice if it threw an error");
|
|
||||||
Console.Error.WriteLine(e);
|
Console.Error.WriteLine(e);
|
||||||
}
|
}
|
||||||
Console.WriteLine("k.");
|
Console.WriteLine($"calendars pulled, scratch has {scratch.agenda.Count} schedulables.");
|
||||||
|
|
||||||
|
foreach (var s in scratch.agenda)
|
||||||
|
{
|
||||||
|
if (s.Showtime - DateTime.Now <= calendarNaptime)
|
||||||
|
{
|
||||||
|
Console.WriteLine("I'm an item on the agenda and showtime is near!");
|
||||||
|
Console.WriteLine(s.Event);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private delegate Schedulable.Schedulable schedulableCreate(CalendarEvent evt);
|
private delegate void schedulableCreate(ref Schedulable.Schedulable creating);
|
||||||
private delegate void schedulableUpdate(Schedulable.Schedulable old, CalendarEvent evt);
|
private static async Task checkCalendar(string calendarUri, string calLabel, schedulableCreate createSchedulable)
|
||||||
private delegate void schedulableRemove(Schedulable.Schedulable removed);
|
|
||||||
private static async Task checkCalendar(string calendarUri, string calLabel,
|
|
||||||
schedulableCreate createSchedulable,
|
|
||||||
schedulableUpdate updateSchedulable,
|
|
||||||
schedulableRemove removeSchedulable)
|
|
||||||
{
|
{
|
||||||
//?export is a hack to allow me to access the calendar
|
//?export is a hack to allow me to access the calendar
|
||||||
//it likes to throw an error saying "this is the webDAV interface, use webDAV" at my webDAV client.
|
//it likes to throw an error saying "this is the webDAV interface, use webDAV" at my webDAV client, stopping me from using webDAV.
|
||||||
var calString = await httpClient.GetStringAsync(conf.webdav_uri + calendarUri + "?export");
|
var calString = await httpClient.GetStringAsync(conf.webdav_uri + calendarUri + "?export");
|
||||||
var calT = Calendar.Load(calString);
|
var calT = Calendar.Load(calString);
|
||||||
var knownChecklist = new List<Schedulable.Schedulable>();
|
var knownChecklist = new List<Schedulable.Schedulable>();
|
||||||
lock (scratch)
|
lock (scratch)
|
||||||
{
|
{
|
||||||
scratch.Calendars[calLabel] = calString;
|
scratch.Calendars[calLabel] = calString;
|
||||||
foreach (var s in scratch.agenda)
|
foreach (var calOccurrence in calT.GetOccurrences(searchStart, searchEnd))
|
||||||
{
|
|
||||||
if (s.Event.Calendar == calT)
|
|
||||||
{
|
|
||||||
knownChecklist.Add(s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
foreach (var evt in calT.Events)
|
|
||||||
{
|
|
||||||
|
|
||||||
if(evt.Start.Value >= searchStart && evt.End.Value <= searchEnd)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"[{calLabel}] hi im an event in the search space, {evt.Summary} on {evt.Start}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
foreach(var calOccurrence in calT.GetOccurrences(searchStart, searchEnd))
|
|
||||||
{
|
{
|
||||||
var asEvent = calOccurrence.Source as Ical.Net.CalendarComponents.CalendarEvent;
|
var asEvent = calOccurrence.Source as Ical.Net.CalendarComponents.CalendarEvent;
|
||||||
Console.WriteLine($"[{calLabel}] hi im an occurence in the search space, {asEvent.Summary} on {calOccurrence.Period.StartTime}");
|
|
||||||
Console.WriteLine($"{asEvent.Uid}");
|
|
||||||
}
|
|
||||||
|
|
||||||
// foreach (var evt in calT.Events)
|
|
||||||
// {
|
|
||||||
// var foundInRange = evt.GetOccurrences(searchStart, searchEnd);
|
|
||||||
// if (foundInRange?.Count > 0)
|
|
||||||
// {
|
|
||||||
// Console.WriteLine($"[{calLabel}] event {evt.Summary} has {foundInRange.Count} occurences");
|
|
||||||
// foreach (var upcoming in foundInRange)
|
|
||||||
// {
|
|
||||||
|
|
||||||
// if (upcoming != null)
|
var newSchedulable = new Schedulable.Schedulable()
|
||||||
// {
|
|
||||||
// Console.WriteLine($"[{calLabel}] event {evt.Summary} has an occurence: {upcoming.Period.StartTime.Date.ToShortDateString()}; uid: {evt.Uid}");
|
|
||||||
// Console.WriteLine($"Description: {evt.Description}");
|
|
||||||
// Console.WriteLine($"Calendar: {evt.Calendar}");
|
|
||||||
// Console.WriteLine($"Children: {evt.Children.Count}");
|
|
||||||
// Console.WriteLine($"Class: {evt.Class}");
|
|
||||||
// Console.WriteLine($"stamp: {evt.DtStamp} created: {evt.Created} start: {evt.DtStart} end: {evt.DtEnd}");
|
|
||||||
// // Console.WriteLine($"Name: {evt.Name}");
|
|
||||||
// // Console.WriteLine($"Parent: {evt.Parent}");
|
|
||||||
// // Console.WriteLine($"Properties: {evt.Properties.Count}");
|
|
||||||
// // if (evt.Properties.Count > 0)
|
|
||||||
// // {
|
|
||||||
// // foreach (var thing in evt.Properties)
|
|
||||||
// // {
|
|
||||||
// // Console.WriteLine($"{thing.Name}: {thing.Value}");
|
|
||||||
// // }
|
|
||||||
// // }
|
|
||||||
// Console.WriteLine($"RecurrenceRules: {evt.RecurrenceRules.Count}");
|
|
||||||
// // var existing = scratch.agenda.FirstOrDefault(s => s.Event.Uid == upcoming);
|
|
||||||
// // if(existing == null)
|
|
||||||
// // {
|
|
||||||
// // scratch.agenda.Add(createSchedulable(upcoming));
|
|
||||||
// // }
|
|
||||||
// // else
|
|
||||||
// // {
|
|
||||||
// // knownChecklist.Remove(existing);
|
|
||||||
// // if(existing.Event != upcoming)
|
|
||||||
// // {
|
|
||||||
// // Console.WriteLine("existing event != new event, but has same uid");
|
|
||||||
// // updateSchedulable(existing, upcoming);
|
|
||||||
// // existing.Event = upcoming;
|
|
||||||
// // }
|
|
||||||
// // }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
if (knownChecklist.Count > 0)
|
|
||||||
{
|
|
||||||
foreach (var removed in knownChecklist)
|
|
||||||
{
|
{
|
||||||
scratch.agenda.Remove(removed);
|
Event = ser.SerializeToString(asEvent),
|
||||||
removeSchedulable(removed);
|
OccurrenceStart = calOccurrence.Period.StartTime.Date,
|
||||||
}
|
OccurrenceEnd = calOccurrence.Period.EndTime.Date,
|
||||||
|
Showtime = calOccurrence.Period.StartTime.Date,
|
||||||
|
};
|
||||||
|
createSchedulable(ref newSchedulable);
|
||||||
|
scratch.agenda.Add(newSchedulable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private static async Task checkTwitch()
|
|
||||||
{
|
|
||||||
await checkCalendar(conf.calendar_twitch, "twitch",
|
|
||||||
(e) => { return new Schedulable.Schedulable() { Event = e }; },
|
|
||||||
(o, e) => { },
|
|
||||||
(o) => { }
|
|
||||||
);
|
|
||||||
}
|
|
||||||
private static async Task checkYoutube()
|
|
||||||
{
|
|
||||||
await checkCalendar(conf.calendar_youtube, "youtube",
|
|
||||||
(e) => { return new Schedulable.Schedulable() { Event = e }; },
|
|
||||||
(o, e) => { },
|
|
||||||
(o) => { }
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,12 @@ namespace Schedulable
|
|||||||
{
|
{
|
||||||
public class Schedulable
|
public class Schedulable
|
||||||
{
|
{
|
||||||
public CalendarEvent Event { get; set; }
|
//no, not calendar event. Circular reference, trips up jsonconvert.
|
||||||
public Occurrence Occurrence { get; set; }
|
public string Event { get; set; }
|
||||||
|
public DateTime OccurrenceStart { get; set; }
|
||||||
|
public DateTime OccurrenceEnd { get; set; }
|
||||||
|
public DateTime Showtime { get; set; }
|
||||||
|
public ScedulableType ScedulableType { get; set; } = ScedulableType.Other;
|
||||||
}
|
}
|
||||||
|
public enum ScedulableType { TwitchStream, YTRelease, Other };
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user