begin absorbing dave
sees events
This commit is contained in:
parent
cf7a724c43
commit
783b1a65a1
9
.gitignore
vendored
9
.gitignore
vendored
@ -60,8 +60,8 @@ BenchmarkDotNet.Artifacts/
|
||||
project.lock.json
|
||||
project.fragment.lock.json
|
||||
artifacts/
|
||||
|
||||
# Tye
|
||||
|
||||
# Tye
|
||||
.tye/
|
||||
|
||||
# StyleCop
|
||||
@ -304,8 +304,8 @@ paket-files/
|
||||
|
||||
# FAKE - F# Make
|
||||
.fake/
|
||||
|
||||
# Ionide - VsCode extension for F# Support
|
||||
|
||||
# Ionide - VsCode extension for F# Support
|
||||
.ionide/
|
||||
|
||||
# CodeRush personal settings
|
||||
@ -446,3 +446,4 @@ $RECYCLE.BIN/
|
||||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
appsettings.json
|
||||
|
13
Config.cs
Normal file
13
Config.cs
Normal 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; }
|
||||
}
|
||||
}
|
96
Program.cs
96
Program.cs
@ -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
36
Scratch.cs
Normal 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));
|
||||
}
|
||||
}
|
||||
}
|
9
appsettings.example.json
Normal file
9
appsettings.example.json
Normal 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"
|
||||
}
|
@ -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>
|
||||
|
10
schedulable/MessageRelay.cs
Normal file
10
schedulable/MessageRelay.cs
Normal 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; }
|
||||
}
|
||||
}
|
8
schedulable/Schedulable.cs
Normal file
8
schedulable/Schedulable.cs
Normal 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
32
schedulable/show/Show.cs
Normal 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
|
||||
}
|
||||
}
|
7
schedulable/show/TwitchStream.cs
Normal file
7
schedulable/show/TwitchStream.cs
Normal file
@ -0,0 +1,7 @@
|
||||
namespace Schedulable.Show
|
||||
{
|
||||
public class TwitchStream : Show
|
||||
{
|
||||
public string TwitchCategory { get; set; }
|
||||
}
|
||||
}
|
7
schedulable/show/YoutubeRelease.cs
Normal file
7
schedulable/show/YoutubeRelease.cs
Normal file
@ -0,0 +1,7 @@
|
||||
namespace Schedulable.Show
|
||||
{
|
||||
public class YoutubeRelease : Show
|
||||
{
|
||||
|
||||
}
|
||||
}
|
4
scratch.json
Normal file
4
scratch.json
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"agenda": [],
|
||||
"Calendars": {}
|
||||
}
|
Loading…
Reference in New Issue
Block a user