Compare commits

...

2 Commits

Author SHA1 Message Date
19be02798c caldav problems
how did this work back in the silver meddlists days?
2023-03-29 13:01:46 -04:00
36c8805ce9 configuration structure update 2023-03-23 16:49:18 -04:00
6 changed files with 105 additions and 11 deletions

View File

@ -8,9 +8,7 @@ namespace newsletter
public class Reporter public class Reporter
{ {
public string ReporterClass { get; set; } public string ReporterClass { get; set; }
public string Url { get; set; } public IEnumerable<KeyValuePair<string, string>> Misc { get; set; }
public string Username { get; set; }
public string Password { get; set; }
} }
} }
} }

View File

@ -79,7 +79,7 @@ namespace newsletter
foreach (var reporterType in reporterTypes) foreach (var reporterType in reporterTypes)
{ {
Console.WriteLine($"{reporterType.ToString().Substring(skipPortionInName).ToLower()} reporter class discovered"); Console.WriteLine($"{reporterType.ToString().Substring(skipPortionInName).ToLower()} reporter class discovered");
Func<Configuration.Reporter, bool> predicate = r => r.ReporterClass == reporterType.ToString().Substring(skipPortionInName).ToLower(); Func<Configuration.Reporter, bool> predicate = r => r.ReporterClass?.ToLower() == reporterType.ToString().Substring(skipPortionInName).ToLower();
if (!conf.Reporters.Any(predicate)) if (!conf.Reporters.Any(predicate))
{ {
Console.WriteLine($"no configurations for it"); Console.WriteLine($"no configurations for it");

View File

@ -1,4 +1,5 @@
using HtmlAgilityPack; using HtmlAgilityPack;
using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace newsletter.Reporters namespace newsletter.Reporters
@ -8,9 +9,16 @@ namespace newsletter.Reporters
#pragma warning disable CS1998 #pragma warning disable CS1998
public override async Task<Report> Report(Configuration.Reporter config) public override async Task<Report> Report(Configuration.Reporter config)
{ {
var sb = new StringBuilder();
sb.AppendLine("dummy node for testing purposes.");
if(config.Misc?.Any() == true)
foreach (var miscConfig in config.Misc)
{
sb.AppendLine($"{miscConfig.Key}: {miscConfig.Value}");
}
return new Report() return new Report()
{ {
ReportContent = HtmlNode.CreateNode($"<div>dummy node for testing purposes. Url: {config.Url}, Username: {config.Username}, Password: {config.Password}.</div>"), ReportContent = HtmlNode.CreateNode($"<div>{sb.ToString()}</div>"),
TextSummary = "dummy text for testing purposes" TextSummary = "dummy text for testing purposes"
}; };
} }

View File

@ -0,0 +1,85 @@
using HtmlAgilityPack;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using CalDAV.NET;//https://github.com/markatk/CalDAV.NET
namespace newsletter.Reporters
{
public class NextcloudCalendars : Reporter
{
public Uri url { get; set; }
public string username_bot { get; set; }
public string password_bot { get; set; }
public string username_self { get; set; }
public string password_self { get; set; }
#pragma warning disable CS1998
public override async Task<Report> Report(Configuration.Reporter config)
{
url = new Uri(config.Misc.FirstOrDefault(kvp => kvp.Key == "url").Value);
username_bot = config.Misc.FirstOrDefault(kvp => kvp.Key == "username_bot").Value;
password_bot = config.Misc.FirstOrDefault(kvp => kvp.Key == "password_bot").Value;
username_self = config.Misc.FirstOrDefault(kvp => kvp.Key == "username_self").Value;
password_self = config.Misc.FirstOrDefault(kvp => kvp.Key == "password_self").Value;
var sb = new StringBuilder();
sb.AppendLine("nextcloud calendars");
var client = new CalDAV.NET.Client(url, username_bot, password_bot);
var cals = await client.GetCalendarsAsync();
if(cals != null && cals.Any())
{
foreach(var cal in cals)
{
sb.AppendLine($"{cal.DisplayName}<br />");
}
}
else
{
sb.AppendLine("no cals found");
}
// var clientParams = new WebDavClientParams
// {
// BaseAddress = url,
// Credentials = new NetworkCredential(username_bot, password_bot)
// };
// using (var client = new WebDavClient(clientParams))
// {
// var result = await client.Propfind(url);
// sb.AppendLine($"{result.StatusCode} - {result.Resources?.Count() ?? 0} items<br />");
// if (result.Resources.Any())
// {
// foreach (var resource in result.Resources)
// {
// if (resource.Uri.EndsWith("/calendars/"))
// {
// sb.AppendLine($"calendars: {resource.Uri}");
// var resutl2 = await client.GetFileResponse if (resutl2.IsSuccessful && resutl2.Resources?.Any() == true)
// {
// foreach (var resource2 in result.Resources)
// {
// sb.AppendLine($"<br />{resource2.DisplayName} - {resource2.Uri} - is collection? {resource2.IsCollection} - {resource2}");
// }
// }
// }
// }
// }
// }
if (config.Misc?.Any() == true)
foreach (var miscConfig in config.Misc)
{
sb.AppendLine($"{miscConfig.Key}: {miscConfig.Value}");
}
return new Report()
{
ReportContent = HtmlNode.CreateNode($"<div>{sb.ToString()}</div>"),
TextSummary = "dummy text for testing purposes"
};
}
#pragma warning restore CS1998
}
}

View File

@ -9,10 +9,11 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="CalDAV.NET" Version="0.1.0-alpha2" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.40" /> <PackageReference Include="HtmlAgilityPack" Version="1.11.40" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="puppeteersharp" Version="5.0.0" /> <PackageReference Include="puppeteersharp" Version="5.0.0" />
<PackageReference Include="WebDav-Client" Version="1.1.2" /> <PackageReference Include="webDav.client" Version="2.8.0" />
<PackageReference Include="Ical.Net" Version="4.2.0" /> <PackageReference Include="Ical.Net" Version="4.2.0" />
</ItemGroup> </ItemGroup>

View File

@ -1,11 +1,13 @@
{ {
"exportPath": "./newsletter.html", "exportPath": "../newsletter.html",
"reporters": [ "reporters": [
{ {
"type":"dummy", "reporterClass":"dummy",
"url": "localhost:8080", "misc":[
"username": "guy who didn't configure", {"key": "url", "value": "localhost:8080"},
"password": "sordph1sh" {"key": "username", "value": "guy who didn't configure"},
{"key": "password", "value": "sordph1sh"}
]
} }
] ]
} }