begin absorbing dave

sees events
This commit is contained in:
Adam R. Grey 2021-08-18 23:16:57 -04:00
parent cf7a724c43
commit 783b1a65a1
13 changed files with 239 additions and 5 deletions

1
.gitignore vendored
View File

@ -446,3 +446,4 @@ $RECYCLE.BIN/
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
appsettings.json

13
Config.cs Normal file
View File

@ -0,0 +1,13 @@
namespace director
{
public class Config
{
public string kafka_bootstrap { get; set; }
public string call_for_humans_discord_webhook { get; set; }
public string webdav_uri { get; set; }
public string webdav_username { get; set; }
public string webdav_password { get; set; }
public string calendar_youtube { get; set; }
public string calendar_twitch { get; set; }
}
}

View File

@ -1,12 +1,106 @@
using System;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using franz;
using Ical.Net;
using Newtonsoft.Json;
namespace director
{
class Program
{
//private static Telefranz tf;
public static Config conf;
private static TimeSpan calendarNaptime = TimeSpan.FromHours(1);
private static Scratch scratch;
private static HttpClient httpClient;
private static DateTime searchStart = DateTime.Now; //is it slower to just call datetime.now every time? /shrug
private static DateTime searchEnd = DateTime.Now.AddDays(7);
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
if (!File.Exists("appsettings.json"))
{
Console.Error.WriteLine("appsettings.json was not found!");
return;
}
conf = JsonConvert.DeserializeObject<Config>(File.ReadAllText("appsettings.json"));
httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(
System.Text.Encoding.ASCII.GetBytes($"{conf.webdav_username}:{conf.webdav_password}")));
//tf = new Telefranz("scheduler", conf.kafka_bootstrap);
//todo: subscribe to event appears message - you don't need to respond to an event disappearing message
//todo: talk to dave. What's coming up in the next short timeframe?
scratch = Scratch.LoadScratch();
while (true)
{
Task.WaitAll(
//await and do next calendar task,
calendarCheck(),
Task.Delay(calendarNaptime)
);
}
}
private static async Task calendarCheck()
{
//pull calendar ics's
try
{
Task.WaitAll(
checkYoutube(),
checkTwitch()
);
}
catch (Exception e)
{
Console.Error.WriteLine("sure would be nice if it threw an error");
Console.Error.WriteLine(e);
}
Console.WriteLine("k.");
lock (scratch)
{
//verify against existing copy, react to changes
//put in scratch
}
}
private static async Task checkTwitch()
{
var calString = await httpClient.GetStringAsync(conf.webdav_uri + conf.calendar_twitch + "?export");
lock(scratch)
{
scratch.Calendars["twitch"] = calString;
}
var calT = Calendar.Load(calString);
Console.WriteLine($"calendar name: {calT.Name}");
foreach(var evt in calT.Events){
var upcoming = evt.GetOccurrences(searchStart, searchEnd)?.FirstOrDefault();
if(upcoming != null){
Console.WriteLine($"[twitch] event {evt.Summary} has an occurence: {upcoming.Period.StartTime}");
}
}
}
private static async Task checkYoutube()
{
var calString = await httpClient.GetStringAsync(conf.webdav_uri + conf.calendar_youtube + "?export");
lock(scratch)
{
scratch.Calendars["youtube"] = calString;
}
var calYT = Calendar.Load(calString);
Console.WriteLine($"calendar name: {calYT.Name}");
foreach(var evt in calYT.Events){
var upcoming = evt.GetOccurrences(searchStart, searchEnd)?.FirstOrDefault();
if(upcoming != null){
Console.WriteLine($"[youtube] event {evt.Summary} has an occurence: {upcoming.Period.StartTime}");
}
}
}
}
}

36
Scratch.cs Normal file
View File

@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json;
using Schedulable;
namespace director
{
public class Scratch
{
private const string path = "scratch.json";
public List<Schedulable.Schedulable> agenda { get; set; } = new List<Schedulable.Schedulable>();
public Dictionary<string, string> Calendars { get; set; } = new Dictionary<string, string>();
//calendar ICSs
public static Scratch LoadScratch()
{
if (File.Exists(path))
{
return JsonConvert.DeserializeObject<Scratch>(File.ReadAllText(path));
}
else
{
var toReturn = new Scratch();
toReturn.Save();
return toReturn;
}
}
public void Save()
{
File.WriteAllText(path, JsonConvert.SerializeObject(this, Formatting.Indented));
}
}
}

6
Show.cs Normal file
View File

@ -0,0 +1,6 @@
namespace director
{
public class Show
{
}
}

9
appsettings.example.json Normal file
View File

@ -0,0 +1,9 @@
{
"kafka_bootstrap": "localhost:9092",
"call_for_humans_discord_webhook": "http://localhost",
"webdav_uri": "http://mywebdav",
"webdav_username": "xX_sephiroth_Xx@aol.com",
"webdav_password": "sw0rdf1sh",
"calendar_youtube": "calendars/1wingedangle/youtube-channel_shared_by_adam",
"calendar_twitch": "calendars/1wingedangle/twitch-channel_shared_by_adam"
}

View File

@ -3,6 +3,13 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<RestoreSources>$(RestoreSources);../packages/nuget/;https://api.nuget.org/v3/index.json</RestoreSources>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="silvermeddlists.franz" Version="0.0.2" />
<PackageReference Include="WebDav.Client" Version="2.7.0" />
<PackageReference Include="Ical.Net" Version="4.2.0" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,10 @@
using System;
namespace Schedulable
{
//You said to echo back a message
public class MessageRelay : Schedulable
{
public silver_messages.message MessageToRelay { get; set; }
}
}

View File

@ -0,0 +1,8 @@
using System;
namespace Schedulable
{
public abstract class Schedulable
{
public DateTime Time { get; set; }
}
}

32
schedulable/show/Show.cs Normal file
View File

@ -0,0 +1,32 @@
using System.Collections.Generic;
namespace Schedulable.Show
{
public class Show
{
public string Name { get; set; }
public Preparation Preperation { get; set; }
public IEnumerable<Phase> Procedure { get; set; }
public TaskList Postshow { get; set; }
}
public class Phase
{
public string Name { get; set; }
}
public class TaskList
{
public IEnumerable<Checklistable> Manual { get; set; }
public IEnumerable<string> Commands { get; set; }
}
public class Preparation : TaskList
{
public IEnumerable<string> AgentsNeeded { get; set; }
public IEnumerable<string> Checks { get; set; }
}
public class Checklistable
{
//for humans
public string Label { get; set; }
public IEnumerable<Checklistable> Items { get; set; } //if no items, just throw up a checkbox
}
}

View File

@ -0,0 +1,7 @@
namespace Schedulable.Show
{
public class TwitchStream : Show
{
public string TwitchCategory { get; set; }
}
}

View File

@ -0,0 +1,7 @@
namespace Schedulable.Show
{
public class YoutubeRelease : Show
{
}
}

4
scratch.json Normal file
View File

@ -0,0 +1,4 @@
{
"agenda": [],
"Calendars": {}
}