-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
92 lines (74 loc) · 3.26 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using CommandLine;
using Ical.Net.CalendarComponents;
using Ical.Net.DataTypes;
using Ical.Net.Serialization;
using System.Security.Cryptography;
using System.Text.RegularExpressions;
using System.Web;
using Calendar = Ical.Net.Calendar;
namespace Splatoon3ics
{
internal class Program
{
static void Main(string[] args)
{
var s3i = new S3I(args);
s3i.Run();
}
class S3I
{
public class Options
{
[Option('u', "scheduleurl", Required = true, HelpText = "GDQ Schedule URL")]
public string? ScheduleUrl { get; set; }
[Option('o', "outputpath", Required = false, HelpText = "Output path")]
public string? OutputPath { get; set; }
}
readonly ParserResult<Options> options;
readonly HttpHelper httpHelper;
readonly MD5 md5;
public S3I(string[] args)
{
options = Parser.Default.ParseArguments<Options>(args);
httpHelper = new HttpHelper();
md5 = MD5.Create();
}
public void Run()
{
options?.WithParsed(o =>
{
if (!string.IsNullOrWhiteSpace(o.ScheduleUrl))
{
var jsonData = HttpUtility.HtmlDecode(httpHelper.GetUrl(o.ScheduleUrl).Result);
var splatData = SplatData.FromJson(jsonData);
var serializer = new CalendarSerializer();
var calendarSalmonrun = ParseSalmonRunSchedule(splatData);
var serializedCalendarSalmonRun = serializer.SerializeToString(calendarSalmonrun);
serializedCalendarSalmonRun = Regex.Replace(serializedCalendarSalmonRun, @"DTSTAMP:.*?\n", "");
File.WriteAllText(o.OutputPath + "salmonrun.ics", serializedCalendarSalmonRun);
}
});
}
private Calendar ParseSalmonRunSchedule(SplatData splatData)
{
var calendar = new Calendar();
calendar.AddTimeZone(TimeZoneInfo.Utc);
foreach (var rotation in splatData.Data.CoopGroupingSchedule.RegularSchedules.Nodes)
{
DateTime dtStart = rotation.StartTime.UtcDateTime.AddSeconds(1);
DateTime dtEnd = rotation.EndTime.UtcDateTime.AddSeconds(-1);
var calEvent = new CalendarEvent()
{
Summary = $"{rotation.Setting.CoopStage.Name} - {rotation.Splatoon3InkKingSalmonidGuess}",
Start = new CalDateTime(dtStart, "Utc"),
End = new CalDateTime(dtEnd, "Utc"),
Location = $"{rotation.Setting.CoopStage.Name}",
Description = $"Weapons:\n{rotation.Setting.Weapons[0].Name}\n{rotation.Setting.Weapons[1].Name}\n{rotation.Setting.Weapons[2].Name}\n{rotation.Setting.Weapons[3].Name}\n\nKing:\n{rotation.Splatoon3InkKingSalmonidGuess}"
};
calendar.Events.Add(calEvent);
}
return calendar;
}
}
}
}