├── LolEsportsApiClient ├── Models │ ├── Outcome.cs │ ├── EventType.cs │ ├── Flag.cs │ ├── Provider.cs │ ├── State.cs │ ├── StrategyType.cs │ ├── Status.cs │ ├── Tournament.cs │ ├── LolEsportsResponse.cs │ ├── Record.cs │ ├── Pages.cs │ ├── Strategy.cs │ ├── Result.cs │ ├── Schedule.cs │ ├── DisplayPriority.cs │ ├── LolEsportsResponseData.cs │ ├── Match.cs │ ├── Stream.cs │ ├── Team.cs │ ├── League.cs │ └── EsportEvent.cs ├── readme.md ├── Options │ └── LolEsportsOptions.cs ├── LolEsportsApiClient.csproj └── LolEsportsClient.cs ├── GoogleCalendarApiClient ├── readme.md ├── GoogleCalendarApiClient.csproj └── Services │ ├── GoogleCalendarServiceCollection.cs │ ├── GoogleCalendarService.cs │ ├── CalendarsService.cs │ ├── CalendarListService.cs │ └── EventsService.cs ├── LolEsportsCalendar ├── readme.md ├── Properties │ └── launchSettings.json ├── Services │ ├── LolEsportsServiceCollection.cs │ └── LolEsportsService.cs ├── appsettings.json ├── Program.cs ├── HourlyBackgroundService.cs └── LolEsportsCalendar.csproj ├── .dockerignore ├── LICENSE ├── Dockerfile ├── LolEsportsCalendar.sln ├── .gitattributes ├── readme.md └── .gitignore /LolEsportsApiClient/Models/Outcome.cs: -------------------------------------------------------------------------------- 1 | namespace LolEsportsApiClient.Models; 2 | 3 | public enum Outcome { loss, win, tie }; 4 | -------------------------------------------------------------------------------- /LolEsportsApiClient/Models/EventType.cs: -------------------------------------------------------------------------------- 1 | namespace LolEsportsApiClient.Models; 2 | 3 | public enum EventType { match, show }; 4 | -------------------------------------------------------------------------------- /LolEsportsApiClient/Models/Flag.cs: -------------------------------------------------------------------------------- 1 | namespace LolEsportsApiClient.Models; 2 | 3 | public enum Flag { hasVod, isSpoiler, hasRecap }; 4 | -------------------------------------------------------------------------------- /LolEsportsApiClient/Models/Provider.cs: -------------------------------------------------------------------------------- 1 | namespace LolEsportsApiClient.Models; 2 | 3 | public enum Provider { trovo, twitch, youtube }; 4 | -------------------------------------------------------------------------------- /LolEsportsApiClient/Models/State.cs: -------------------------------------------------------------------------------- 1 | namespace LolEsportsApiClient.Models; 2 | 3 | public enum State { completed, inProgress, unstarted }; 4 | -------------------------------------------------------------------------------- /LolEsportsApiClient/Models/StrategyType.cs: -------------------------------------------------------------------------------- 1 | namespace LolEsportsApiClient.Models; 2 | 3 | public enum StrategyType { bestOf, playAll }; 4 | -------------------------------------------------------------------------------- /LolEsportsApiClient/Models/Status.cs: -------------------------------------------------------------------------------- 1 | namespace LolEsportsApiClient.Models; 2 | 3 | public enum Status { forceSelected, hidden, notSelected, selected }; 4 | -------------------------------------------------------------------------------- /LolEsportsApiClient/readme.md: -------------------------------------------------------------------------------- 1 | # Disclaimer 2 | LolEsports.com does not have any public information about their API. 3 | Please be carefull and use at your own risk. 4 | -------------------------------------------------------------------------------- /LolEsportsApiClient/Models/Tournament.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace LolEsportsApiClient.Models; 4 | 5 | public partial class Tournament 6 | { 7 | [JsonProperty("id")] 8 | public required string Id { get; set; } 9 | } 10 | -------------------------------------------------------------------------------- /GoogleCalendarApiClient/readme.md: -------------------------------------------------------------------------------- 1 | # References 2 | - https://developers.google.com/calendar/api/v3/reference/ 3 | - https://developers.google.com/resources/api-libraries/documentation/calendar/v3/csharp/latest/namespaceGoogle_1_1Apis_1_1Calendar_1_1v3_1_1Data.html -------------------------------------------------------------------------------- /LolEsportsApiClient/Models/LolEsportsResponse.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace LolEsportsApiClient.Models; 4 | 5 | public partial class LolEsportsResponse 6 | { 7 | [JsonProperty("data")] 8 | public TResponseDataType? Data { get; set; } 9 | } 10 | -------------------------------------------------------------------------------- /LolEsportsCalendar/readme.md: -------------------------------------------------------------------------------- 1 | # Setup 2 | Follow [.NET quickstart](https://developers.google.com/calendar/api/quickstart/dotnet#step_2_set_up_the_sample) for GoogleCalendarAPI credentials.json. 3 | Go to [LolEsports](https://lolesports.com/) and find your api-key, paste it inside lolesports-credentials.json -------------------------------------------------------------------------------- /LolEsportsApiClient/Models/Record.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace LolEsportsApiClient.Models; 4 | 5 | public partial class Record 6 | { 7 | [JsonProperty("wins")] 8 | public long Wins { get; set; } 9 | 10 | [JsonProperty("losses")] 11 | public long Losses { get; set; } 12 | } 13 | -------------------------------------------------------------------------------- /LolEsportsApiClient/Models/Pages.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace LolEsportsApiClient.Models; 4 | 5 | public partial class Pages 6 | { 7 | [JsonProperty("older")] 8 | public string? Older { get; set; } 9 | 10 | [JsonProperty("newer")] 11 | public string? Newer { get; set; } 12 | } 13 | -------------------------------------------------------------------------------- /LolEsportsApiClient/Models/Strategy.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace LolEsportsApiClient.Models; 4 | 5 | public partial class Strategy 6 | { 7 | [JsonProperty("type")] 8 | public StrategyType Type { get; set; } 9 | 10 | [JsonProperty("count")] 11 | public long Count { get; set; } 12 | } 13 | -------------------------------------------------------------------------------- /LolEsportsApiClient/Models/Result.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace LolEsportsApiClient.Models; 4 | 5 | public partial class Result 6 | { 7 | [JsonProperty("outcome")] 8 | public Outcome? Outcome { get; set; } 9 | 10 | [JsonProperty("gameWins")] 11 | public long GameWins { get; set; } 12 | } 13 | -------------------------------------------------------------------------------- /LolEsportsApiClient/Options/LolEsportsOptions.cs: -------------------------------------------------------------------------------- 1 | namespace LolEsportsApiClient.Options; 2 | 3 | public class LolEsportsOptions 4 | { 5 | public const string SectionName = "LolEsports"; 6 | public required string ApiKey { get; set; } 7 | public required string BaseUrl { get; set; } 8 | public string[]? Leagues { get; set; } 9 | } 10 | -------------------------------------------------------------------------------- /LolEsportsApiClient/Models/Schedule.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System.Collections.Generic; 3 | 4 | namespace LolEsportsApiClient.Models; 5 | 6 | public partial class Schedule 7 | { 8 | [JsonProperty("pages")] 9 | public Pages? Pages { get; set; } 10 | 11 | [JsonProperty("events")] 12 | public List Events { get; set; } = []; 13 | } 14 | -------------------------------------------------------------------------------- /LolEsportsApiClient/Models/DisplayPriority.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace LolEsportsApiClient.Models; 4 | 5 | public partial class DisplayPriority 6 | { 7 | [JsonProperty("position")] 8 | public long Position { get; set; } 9 | 10 | [JsonProperty("status")] 11 | // public Status Status { get; set; } 12 | public string? Status { get; set; } 13 | } 14 | -------------------------------------------------------------------------------- /LolEsportsCalendar/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "profiles": { 3 | "LolEsportsCalendar": { 4 | "commandName": "Project", 5 | "ASPNETCORE_ENVIRONMENT": "Development" 6 | }, 7 | "Docker": { 8 | "commandName": "Docker", 9 | "ASPNETCORE_ENVIRONMENT": "Production" 10 | }, 11 | "Profile 1": { 12 | "commandName": "Project", 13 | "ASPNETCORE_ENVIRONMENT": "Development" 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /.dockerignore: -------------------------------------------------------------------------------- 1 | **/.classpath 2 | **/.dockerignore 3 | **/.env 4 | **/.git 5 | **/.gitignore 6 | **/.project 7 | **/.settings 8 | **/.toolstarget 9 | **/.vs 10 | **/.vscode 11 | **/*.*proj.user 12 | **/*.dbmdl 13 | **/*.jfm 14 | **/azds.yaml 15 | **/bin 16 | **/charts 17 | **/docker-compose* 18 | **/Dockerfile* 19 | **/node_modules 20 | **/*.log 21 | **/npm-debug.log 22 | **/obj 23 | **/secrets.* 24 | **/values.dev.yaml 25 | LICENSE 26 | README.md 27 | Logs/** -------------------------------------------------------------------------------- /LolEsportsApiClient/Models/LolEsportsResponseData.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System.Collections.Generic; 3 | 4 | namespace LolEsportsApiClient.Models; 5 | 6 | public class LolEsportsLeaguesResponseData 7 | { 8 | [JsonProperty("leagues")] 9 | public List Leagues { get; set; } = []; 10 | } 11 | 12 | public class LolEsportsScheduleResponseData 13 | { 14 | [JsonProperty("schedule")] 15 | public required Schedule Schedule { get; set; } 16 | } 17 | -------------------------------------------------------------------------------- /LolEsportsApiClient/Models/Match.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System.Collections.Generic; 3 | 4 | namespace LolEsportsApiClient.Models; 5 | 6 | public partial class Match 7 | { 8 | [JsonProperty("id")] 9 | public string? Id { get; set; } 10 | 11 | [JsonProperty("flags")] 12 | public List Flags { get; set; } = []; 13 | 14 | [JsonProperty("teams")] 15 | public List Teams { get; set; } = []; 16 | 17 | [JsonProperty("strategy")] 18 | public Strategy? Strategy { get; set; } 19 | } 20 | -------------------------------------------------------------------------------- /LolEsportsApiClient/Models/Stream.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace LolEsportsApiClient.Models; 4 | 5 | public partial class Stream 6 | { 7 | [JsonProperty("parameter")] 8 | public string? Parameter { get; set; } 9 | 10 | [JsonProperty("locale")] 11 | public string? Locale { get; set; } 12 | 13 | [JsonProperty("provider")] 14 | public Provider Provider { get; set; } 15 | 16 | [JsonProperty("countries")] 17 | public string[] Countries { get; set; } = []; 18 | 19 | [JsonProperty("offset")] 20 | public long Offset { get; set; } 21 | } 22 | -------------------------------------------------------------------------------- /LolEsportsApiClient/Models/Team.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | using System.Diagnostics; 4 | 5 | namespace LolEsportsApiClient.Models; 6 | 7 | [DebuggerDisplay("{Code,nq} - {Name,nq}")] 8 | public partial class Team 9 | { 10 | [JsonProperty("name")] 11 | public required string Name { get; set; } 12 | 13 | [JsonProperty("code")] 14 | public required string Code { get; set; } 15 | 16 | [JsonProperty("image")] 17 | public Uri? Image { get; set; } 18 | 19 | [JsonProperty("result")] 20 | public Result? Result { get; set; } 21 | 22 | [JsonProperty("record")] 23 | public Record? Record { get; set; } 24 | } 25 | -------------------------------------------------------------------------------- /GoogleCalendarApiClient/GoogleCalendarApiClient.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | enable 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /LolEsportsApiClient/LolEsportsApiClient.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | enable 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /LolEsportsApiClient/Models/League.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | using System.Diagnostics; 4 | 5 | namespace LolEsportsApiClient.Models; 6 | 7 | [DebuggerDisplay("{Region,nq} - {Name,nq}")] 8 | public partial class League 9 | { 10 | [JsonProperty("id")] 11 | public required string Id { get; set; } 12 | 13 | [JsonProperty("slug")] 14 | public required string Slug { get; set; } 15 | 16 | [JsonProperty("name")] 17 | public required string Name { get; set; } 18 | 19 | [JsonProperty("region")] 20 | public required string Region { get; set; } 21 | 22 | [JsonProperty("image")] 23 | public Uri? Image { get; set; } 24 | 25 | [JsonProperty("priority")] 26 | public long Priority { get; set; } 27 | 28 | [JsonProperty("displayPriority")] 29 | public DisplayPriority? DisplayPriority { get; set; } 30 | } 31 | -------------------------------------------------------------------------------- /LolEsportsApiClient/Models/EsportEvent.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | using System.Diagnostics; 4 | 5 | namespace LolEsportsApiClient.Models; 6 | 7 | [DebuggerDisplay("{BlockName,nq} - {League.Name,nq}")] 8 | public partial class EsportEvent 9 | { 10 | [JsonProperty("id")] 11 | public string? Id { get; set; } 12 | 13 | [JsonProperty("startTime")] 14 | public DateTimeOffset StartTime { get; set; } 15 | 16 | [JsonProperty("state")] 17 | public State State { get; set; } 18 | 19 | [JsonProperty("type")] 20 | public EventType Type { get; set; } 21 | 22 | [JsonProperty("blockName")] 23 | public string? BlockName { get; set; } 24 | 25 | [JsonProperty("league")] 26 | public League? League { get; set; } 27 | 28 | [JsonProperty("match", NullValueHandling = NullValueHandling.Ignore)] 29 | public required Match Match { get; set; } 30 | } -------------------------------------------------------------------------------- /LolEsportsCalendar/Services/LolEsportsServiceCollection.cs: -------------------------------------------------------------------------------- 1 | using LolEsportsApiClient; 2 | using LolEsportsApiClient.Options; 3 | using Microsoft.Extensions.Configuration; 4 | using Microsoft.Extensions.DependencyInjection; 5 | using System; 6 | 7 | namespace LolEsportsCalendar.Services; 8 | 9 | public static class LolEsportsServiceCollection 10 | { 11 | public static IServiceCollection AddLeagueEsportService(this IServiceCollection services, IConfiguration configuration) 12 | { 13 | services.AddSingleton(); 14 | services.AddHttpClient((serviceProvider, httpClient) => { 15 | LolEsportsOptions? lolEsportOptions = configuration.Get() ?? throw new InvalidOperationException("LolEsportsOptions is required"); 16 | 17 | httpClient.BaseAddress = new Uri(lolEsportOptions.BaseUrl); 18 | httpClient.DefaultRequestHeaders.Add("x-api-key", lolEsportOptions.ApiKey); 19 | }); 20 | 21 | return services; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /LolEsportsCalendar/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "System.Net.Http.HttpClient": "Warning" 6 | } 7 | }, 8 | "Serilog": { 9 | "Using": [ 10 | "Serilog.Sinks.Console", 11 | "Serilog.Sinks.File" 12 | ], 13 | "MinimumLevel": { 14 | "Default": "Information", 15 | "Override": { 16 | "Microsoft": "Warning", 17 | "System": "Warning", 18 | "System.Net.Http.HttpClient": "Warning" 19 | } 20 | }, 21 | "WriteTo": [ 22 | { 23 | "Name": "Console" 24 | }, 25 | { 26 | "Name": "File", 27 | "Args": { 28 | "path": "./Logs/log-.txt", 29 | "rollingInterval": "Day" 30 | } 31 | } 32 | ], 33 | "Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ], 34 | "Properties": { 35 | "Application": "LolEsportsCalendar" 36 | } 37 | }, 38 | "LolEsports": { 39 | "BaseUrl": "https://esports-api.lolesports.com", 40 | "ApiKey": "0TvQnueqKa5mxJntVWt0w4LpLfEkrV1Ta8rQBb9Z", 41 | "Leagues": [] 42 | } 43 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2025 ArnoutPullen 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /LolEsportsCalendar/Program.cs: -------------------------------------------------------------------------------- 1 | using GoogleCalendarApiClient.Services; 2 | using LolEsportsApiClient.Options; 3 | using LolEsportsCalendar; 4 | using LolEsportsCalendar.Services; 5 | using Microsoft.Extensions.Configuration; 6 | using Microsoft.Extensions.DependencyInjection; 7 | using Microsoft.Extensions.Hosting; 8 | using Microsoft.Extensions.Logging; 9 | using Serilog; 10 | 11 | var builder = Host.CreateApplicationBuilder(); 12 | builder.Configuration.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true); 13 | 14 | builder.Services.AddLogging(config => { 15 | config.ClearProviders(); 16 | config.AddSerilog(new LoggerConfiguration() 17 | .ReadFrom.Configuration(builder.Configuration) // Read from appsettings.json 18 | .CreateLogger()); 19 | }); 20 | 21 | builder.Services.AddOptions().BindConfiguration(LolEsportsOptions.SectionName).ValidateOnStart(); 22 | 23 | // Configure services 24 | builder.Services.AddGoogleCalendarService(); 25 | builder.Services.AddHostedService(); 26 | builder.Services.AddLeagueEsportService(builder.Configuration.GetSection(LolEsportsOptions.SectionName)); 27 | 28 | // Run 29 | await builder.Build().RunAsync(); -------------------------------------------------------------------------------- /LolEsportsCalendar/HourlyBackgroundService.cs: -------------------------------------------------------------------------------- 1 | using LolEsportsCalendar.Services; 2 | using Microsoft.Extensions.Hosting; 3 | using Microsoft.Extensions.Logging; 4 | using Serilog; 5 | using System; 6 | using System.Threading; 7 | using System.Threading.Tasks; 8 | 9 | namespace LolEsportsCalendar; 10 | 11 | class HourlyBackgroundService(ILogger logger, 12 | LolEsportsService lolEsportsService) : IHostedService, IDisposable 13 | { 14 | private readonly PeriodicTimer periodicTimer = new(TimeSpan.FromHours(1)); 15 | 16 | public async Task StartAsync(CancellationToken cancellationToken) 17 | { 18 | logger.LogInformation("Background Hosted Service running."); 19 | 20 | // Import events once 21 | await lolEsportsService.ImportEvents(cancellationToken); 22 | 23 | // Import events every hour 24 | while (await periodicTimer.WaitForNextTickAsync(cancellationToken)) 25 | { 26 | try 27 | { 28 | await lolEsportsService.ImportEvents(cancellationToken); 29 | } 30 | catch (OperationCanceledException) 31 | { 32 | logger.LogInformation("Background Hosted Service is stopping."); 33 | } 34 | catch (Exception exception) 35 | { 36 | logger.LogError(exception, "Error while importing events"); 37 | } 38 | } 39 | } 40 | 41 | public async Task StopAsync(CancellationToken cancellationToken) 42 | { 43 | logger.LogInformation("Background Hosted Service is stopping."); 44 | await Log.CloseAndFlushAsync(); 45 | } 46 | 47 | public void Dispose() 48 | { 49 | periodicTimer?.Dispose(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging. 2 | 3 | # This stage is used when running from VS in fast mode (Default for Debug configuration) 4 | # FROM mcr.microsoft.com/dotnet/runtime:8.0 AS base 5 | FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base 6 | WORKDIR /app 7 | # Optionally, if you need to set a user, you can uncomment and define the user variable. 8 | # USER $APP_UID 9 | 10 | # This stage is used to build the service project 11 | FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build 12 | ARG BUILD_CONFIGURATION=Release 13 | WORKDIR /src 14 | 15 | # Copy project files 16 | COPY ["LolEsportsCalendar/LolEsportsCalendar.csproj", "LolEsportsCalendar/"] 17 | COPY ["GoogleCalendarApiClient/GoogleCalendarApiClient.csproj", "GoogleCalendarApiClient/"] 18 | COPY ["LolEsportsApiClient/LolEsportsApiClient.csproj", "LolEsportsApiClient/"] 19 | 20 | # Restore dependencies 21 | RUN dotnet restore "./LolEsportsCalendar/LolEsportsCalendar.csproj" 22 | 23 | # Copy the rest of the application code 24 | COPY . . 25 | 26 | # Build the application 27 | WORKDIR "/src/LolEsportsCalendar" 28 | RUN dotnet build "./LolEsportsCalendar.csproj" -c $BUILD_CONFIGURATION -o /app/build 29 | 30 | # This stage is used to publish the service project to be copied to the final stage 31 | FROM build AS publish 32 | RUN dotnet publish "./LolEsportsCalendar.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false 33 | 34 | # This stage is used in production or when running from VS in regular mode (Default when not using the Debug configuration) 35 | FROM base AS final 36 | WORKDIR /app 37 | 38 | # Copy the published output from the previous stage 39 | COPY --from=publish /app/publish . 40 | 41 | # Set entry point for the container to run the app 42 | ENTRYPOINT ["dotnet", "LolEsportsCalendar.dll"] -------------------------------------------------------------------------------- /GoogleCalendarApiClient/Services/GoogleCalendarServiceCollection.cs: -------------------------------------------------------------------------------- 1 | using Google.Apis.Auth.OAuth2; 2 | using Google.Apis.Calendar.v3; 3 | using Google.Apis.Services; 4 | using Google.Apis.Util.Store; 5 | using Microsoft.Extensions.DependencyInjection; 6 | using System.IO; 7 | using System.Threading; 8 | using System.Threading.Tasks; 9 | 10 | namespace GoogleCalendarApiClient.Services; 11 | 12 | public static class GoogleCalendarServiceCollection 13 | { 14 | public static IServiceCollection AddGoogleCalendarService(this IServiceCollection services) 15 | { 16 | // Google Calendar API 17 | var userCredential = GetUserCredentialAsync().GetAwaiter().GetResult(); 18 | 19 | services.AddSingleton(); 20 | services.AddSingleton(); 21 | services.AddSingleton(); 22 | services.AddSingleton(); 23 | services.AddSingleton(_ => new CalendarService(new BaseClientService.Initializer() 24 | { 25 | HttpClientInitializer = userCredential, 26 | ApplicationName = "LolEsportsCalendar" 27 | })); 28 | 29 | return services; 30 | } 31 | 32 | public static async Task GetUserCredentialAsync() 33 | { 34 | using var stream = 35 | new FileStream("credentials.json", FileMode.Open, FileAccess.Read); 36 | 37 | // The file token.json stores the user's access and refresh tokens, and is created 38 | // automatically when the authorization flow completes for the first time. 39 | GoogleClientSecrets googleClientSecrets = await GoogleClientSecrets.FromStreamAsync(stream); 40 | 41 | return await GoogleWebAuthorizationBroker.AuthorizeAsync( 42 | googleClientSecrets.Secrets, 43 | [CalendarService.Scope.Calendar, CalendarService.Scope.CalendarEvents], 44 | "user", 45 | CancellationToken.None, 46 | new FileDataStore("token.json", true)); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /LolEsportsCalendar/LolEsportsCalendar.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | Windows 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 | Always 34 | 35 | 36 | Always 37 | 38 | 39 | Always 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /LolEsportsCalendar.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.30907.101 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LolEsportsCalendar", "LolEsportsCalendar\LolEsportsCalendar.csproj", "{CCC0DDA8-2B4A-45A1-AF80-2C8646ED747E}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LolEsportsApiClient", "LolEsportsApiClient\LolEsportsApiClient.csproj", "{5F29631C-16FD-4CB4-94ED-CBB7E8E66AB7}" 9 | EndProject 10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GoogleCalendarApiClient", "GoogleCalendarApiClient\GoogleCalendarApiClient.csproj", "{3AAD04B3-66C3-4B0C-8CB2-A0B46B0B44BC}" 11 | EndProject 12 | Global 13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 14 | Debug|Any CPU = Debug|Any CPU 15 | Release|Any CPU = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {CCC0DDA8-2B4A-45A1-AF80-2C8646ED747E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {CCC0DDA8-2B4A-45A1-AF80-2C8646ED747E}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {CCC0DDA8-2B4A-45A1-AF80-2C8646ED747E}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {CCC0DDA8-2B4A-45A1-AF80-2C8646ED747E}.Release|Any CPU.Build.0 = Release|Any CPU 22 | {5F29631C-16FD-4CB4-94ED-CBB7E8E66AB7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 23 | {5F29631C-16FD-4CB4-94ED-CBB7E8E66AB7}.Debug|Any CPU.Build.0 = Debug|Any CPU 24 | {5F29631C-16FD-4CB4-94ED-CBB7E8E66AB7}.Release|Any CPU.ActiveCfg = Release|Any CPU 25 | {5F29631C-16FD-4CB4-94ED-CBB7E8E66AB7}.Release|Any CPU.Build.0 = Release|Any CPU 26 | {3AAD04B3-66C3-4B0C-8CB2-A0B46B0B44BC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {3AAD04B3-66C3-4B0C-8CB2-A0B46B0B44BC}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {3AAD04B3-66C3-4B0C-8CB2-A0B46B0B44BC}.Release|Any CPU.ActiveCfg = Release|Any CPU 29 | {3AAD04B3-66C3-4B0C-8CB2-A0B46B0B44BC}.Release|Any CPU.Build.0 = Release|Any CPU 30 | EndGlobalSection 31 | GlobalSection(SolutionProperties) = preSolution 32 | HideSolutionNode = FALSE 33 | EndGlobalSection 34 | GlobalSection(ExtensibilityGlobals) = postSolution 35 | SolutionGuid = {8AE3B969-E045-40CE-8973-F7AA373A9588} 36 | EndGlobalSection 37 | EndGlobal 38 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /GoogleCalendarApiClient/Services/GoogleCalendarService.cs: -------------------------------------------------------------------------------- 1 | using Google.Apis.Calendar.v3.Data; 2 | using LolEsportsApiClient.Models; 3 | using Microsoft.Extensions.Logging; 4 | using System; 5 | using System.Collections.Generic; 6 | 7 | namespace GoogleCalendarApiClient.Services; 8 | 9 | public class GoogleCalendarService 10 | { 11 | private readonly Dictionary calendarLookup = []; 12 | private readonly CalendarsService _calendarsService; 13 | private readonly CalendarListService _calendarListService; 14 | private readonly ILogger _logger; 15 | 16 | public GoogleCalendarService(CalendarsService calendarsService, CalendarListService calendarListService, ILogger logger) 17 | { 18 | _logger = logger; 19 | _calendarsService = calendarsService; 20 | _calendarListService = calendarListService; 21 | 22 | BuildCalendarLookup(); 23 | } 24 | 25 | public void BuildCalendarLookup() 26 | { 27 | // View 28 | CalendarList calendarList = _calendarListService.List(); 29 | 30 | // Add calendars to lookup 31 | foreach (var calendar in calendarList.Items) 32 | { 33 | if (!calendarLookup.ContainsKey(calendar.Summary)) 34 | { 35 | calendarLookup.Add(calendar.Summary, calendar.Id); 36 | } 37 | } 38 | } 39 | 40 | public Dictionary GetCalendarLookup() 41 | { 42 | return calendarLookup; 43 | } 44 | 45 | public Calendar? InsertLeagueAsCalendar(League league) 46 | { 47 | Calendar? newCalendar = null; 48 | Calendar calendar = ConvertLeagueToCalendar(league); 49 | 50 | try 51 | { 52 | newCalendar = _calendarsService.Insert(calendar); 53 | } 54 | catch (Exception exception) 55 | { 56 | _logger.LogError(exception, "Error while creating calendar: {CalendarSummary}", calendar.Summary); 57 | } 58 | 59 | if (newCalendar != null) 60 | { 61 | _logger.LogInformation("Created calendar {CalendarSummary}", calendar.Summary); 62 | calendarLookup.Add(calendar.Summary, calendar.Id); 63 | } 64 | 65 | return newCalendar; 66 | } 67 | 68 | public static Calendar ConvertLeagueToCalendar(League league) 69 | { 70 | Calendar calendar = new() 71 | { 72 | Summary = league.Name, 73 | Description = league.Name + " / " + league.Region, 74 | }; 75 | 76 | return calendar; 77 | } 78 | 79 | public static Event ConvertEsportEventToGoogleEvent(EsportEvent esportEvent) 80 | { 81 | if (esportEvent.Match == null) throw new MissingMemberException("EsportEvent is missing match property"); 82 | 83 | Event @event = new() 84 | { 85 | Id = esportEvent.Match.Id, 86 | Start = new EventDateTime { DateTimeDateTimeOffset = esportEvent.StartTime.UtcDateTime }, 87 | End = new EventDateTime { DateTimeDateTimeOffset = esportEvent.StartTime.UtcDateTime.AddHours(1) }, 88 | Summary = esportEvent.Match.Teams[0].Code + " vs " + esportEvent.Match.Teams[1].Code 89 | }; 90 | 91 | return @event; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /LolEsportsApiClient/LolEsportsClient.cs: -------------------------------------------------------------------------------- 1 | using LolEsportsApiClient.Models; 2 | using System.Collections.Generic; 3 | using System.Collections.Specialized; 4 | using System.Net.Http; 5 | using System.Threading; 6 | using System.Threading.Tasks; 7 | using System.Web; 8 | 9 | namespace LolEsportsApiClient; 10 | 11 | public class LolEsportsClient(HttpClient httpClient) 12 | { 13 | private List? _leagues = null; 14 | 15 | public async Task> GetLeaguesAsync(CancellationToken cancellationToken = default) 16 | { 17 | var leaguesResponseData = await GetDataAsync("/persisted/gw/getLeagues" + DictionaryToQueryString(), cancellationToken); 18 | 19 | return leaguesResponseData?.Leagues ?? []; 20 | } 21 | 22 | public async Task GetLeagueByName(string leagueName, CancellationToken cancellationToken = default) 23 | { 24 | _leagues ??= await GetLeaguesAsync(cancellationToken); 25 | 26 | foreach (League league in _leagues) 27 | { 28 | if (league.Name.Equals(leagueName, System.StringComparison.CurrentCultureIgnoreCase) 29 | || league.Slug.Equals(leagueName, System.StringComparison.CurrentCultureIgnoreCase)) 30 | { 31 | return league; 32 | } 33 | } 34 | 35 | return null; 36 | } 37 | 38 | public void ClearLeaguesCache() 39 | { 40 | _leagues = null; 41 | } 42 | 43 | public async Task> GetScheduleAsync(CancellationToken cancellationToken = default) 44 | { 45 | var leaguesResponseData = await GetDataAsync("/persisted/gw/getSchedule" + DictionaryToQueryString(), cancellationToken); 46 | 47 | return leaguesResponseData?.Schedule.Events ?? []; 48 | } 49 | 50 | public async Task GetScheduleByLeagueAsync(League league, string? page, CancellationToken cancellationToken = default) 51 | { 52 | Dictionary query = new() 53 | { 54 | { "leagueId", league.Id } 55 | }; 56 | 57 | if (!string.IsNullOrEmpty(page)) 58 | { 59 | query.Add("pageToken", page); 60 | } 61 | 62 | return await GetDataAsync("/persisted/gw/getSchedule" + DictionaryToQueryString(query), cancellationToken); 63 | } 64 | 65 | private async Task GetDataAsync(string path, CancellationToken cancellationToken = default) 66 | { 67 | var response = await httpClient.GetAsync(path, cancellationToken); 68 | 69 | if (!response.IsSuccessStatusCode) 70 | { 71 | throw new HttpRequestException("Response not ok"); 72 | } 73 | 74 | LolEsportsResponse data = await response.Content.ReadAsAsync>(cancellationToken); 75 | return data.Data; 76 | } 77 | 78 | private static string DictionaryToQueryString(Dictionary? query = null) 79 | { 80 | NameValueCollection queryString = HttpUtility.ParseQueryString(string.Empty); 81 | 82 | query ??= []; 83 | 84 | queryString.Add("hl", "en-GB"); 85 | 86 | foreach (var item in query) 87 | { 88 | queryString.Add(item.Key, item.Value); 89 | } 90 | 91 | return '?' + queryString.ToString(); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /GoogleCalendarApiClient/Services/CalendarsService.cs: -------------------------------------------------------------------------------- 1 | using Google.Apis.Calendar.v3; 2 | using Google.Apis.Calendar.v3.Data; 3 | using Microsoft.Extensions.Logging; 4 | using System; 5 | using static Google.Apis.Calendar.v3.CalendarsResource; 6 | 7 | namespace GoogleCalendarApiClient.Services; 8 | 9 | public class CalendarsService(CalendarService calendarService, ILogger logger) 10 | { 11 | 12 | /// Returns metadata for a calendar. 13 | /// 14 | /// 15 | public Calendar? Get(string calendarId) 16 | { 17 | Calendar? calendar = null; 18 | 19 | try 20 | { 21 | GetRequest getRequest = calendarService.Calendars.Get(calendarId); 22 | calendar = getRequest.Execute(); 23 | } 24 | catch (Exception exception) 25 | { 26 | logger.LogError(exception, "Error while getting Calendar with id {CalendarId}", calendarId); 27 | } 28 | 29 | return calendar; 30 | } 31 | 32 | /// Creates a secondary calendar. 33 | /// 34 | /// 35 | public Calendar Insert(Calendar calendar) 36 | { 37 | InsertRequest insertRequest = calendarService.Calendars.Insert(calendar); 38 | Calendar newCalendar = insertRequest.Execute(); 39 | 40 | return newCalendar; 41 | } 42 | 43 | public Calendar InsertOrUpdate(Calendar calendar, string calendarId) 44 | { 45 | Calendar _calendar; 46 | Calendar? exists = Get(calendar.Id); 47 | 48 | if (exists == null) 49 | { 50 | _calendar = Insert(calendar); 51 | } 52 | else 53 | { 54 | _calendar = Update(calendar, calendarId); 55 | } 56 | 57 | return _calendar; 58 | } 59 | 60 | /// Updates metadata for a calendar. 61 | /// 62 | /// 63 | public Calendar Update(Calendar calendar, string calendarId) 64 | { 65 | UpdateRequest updateRequest = calendarService.Calendars.Update(calendar, calendarId); 66 | Calendar updatedCalendar = updateRequest.Execute(); 67 | 68 | return updatedCalendar; 69 | } 70 | 71 | /// Updates metadata for a calendar. This method supports patch semantics. 72 | /// 73 | /// 74 | public Calendar Patch(Calendar calendar, string calendarId) 75 | { 76 | PatchRequest patchRequest = calendarService.Calendars.Patch(calendar, calendarId); 77 | Calendar patchedCalendar = patchRequest.Execute(); 78 | 79 | return patchedCalendar; 80 | } 81 | 82 | /// Clears a primary calendar. This operation deletes all events associated with the primary calendar of an account. 83 | /// 84 | /// 85 | public string Clear(string calendarId) 86 | { 87 | ClearRequest clearRequest = calendarService.Calendars.Clear(calendarId); 88 | string cleared = clearRequest.Execute(); 89 | 90 | return cleared; 91 | } 92 | 93 | /// Deletes a secondary calendar. Use CalendarsService.Clear for clearing all events on primary calendars. 94 | /// 95 | /// 96 | public string Delete(string calendarId) 97 | { 98 | DeleteRequest deleteRequest = calendarService.Calendars.Delete(calendarId); 99 | string deleted = deleteRequest.Execute(); 100 | 101 | return deleted; 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /GoogleCalendarApiClient/Services/CalendarListService.cs: -------------------------------------------------------------------------------- 1 | using Google.Apis.Calendar.v3; 2 | using Google.Apis.Calendar.v3.Data; 3 | using Microsoft.Extensions.Logging; 4 | using System; 5 | using static Google.Apis.Calendar.v3.CalendarListResource; 6 | 7 | namespace GoogleCalendarApiClient.Services; 8 | 9 | public class CalendarListService(CalendarService calendarService, ILogger logger) 10 | { 11 | /// Returns the calendars on the user's calendar list. 12 | /// 13 | /// 14 | public CalendarList List() 15 | { 16 | ListRequest listRequest = calendarService.CalendarList.List(); 17 | CalendarList calendarList = listRequest.Execute(); 18 | 19 | return calendarList; 20 | } 21 | 22 | /// Returns a calendar from the user's calendar list. 23 | /// 24 | /// 25 | public CalendarListEntry? Get(string calendarId) 26 | { 27 | CalendarListEntry? calendarListEntry = null; 28 | 29 | try 30 | { 31 | GetRequest getRequest = calendarService.CalendarList.Get(calendarId); 32 | calendarListEntry = getRequest.Execute(); 33 | } 34 | catch (Exception exception) 35 | { 36 | logger.LogError(exception, "Error while getting CalendarListEntry with id {CalendarId}", calendarId); 37 | } 38 | 39 | return calendarListEntry; 40 | } 41 | 42 | /// Watch for changes to CalendarList resources. 43 | /// 44 | /// 45 | public Channel Watch(Channel body) 46 | { 47 | WatchRequest watchRequest = calendarService.CalendarList.Watch(body); 48 | Channel channel = watchRequest.Execute(); 49 | 50 | return channel; 51 | } 52 | 53 | /// Inserts an existing calendar into the user's calendar list. 54 | /// 55 | /// 56 | public CalendarListEntry Insert(CalendarListEntry calendar) 57 | { 58 | InsertRequest insertRequest = calendarService.CalendarList.Insert(calendar); 59 | var calendarListEntry = insertRequest.Execute(); 60 | 61 | return calendarListEntry; 62 | } 63 | 64 | public CalendarListEntry InsertOrUpdate(CalendarListEntry calendar, string calendarId) 65 | { 66 | CalendarListEntry calendarListEntry; 67 | CalendarListEntry? exists = Get(calendar.Id); 68 | 69 | if (exists == null) 70 | { 71 | calendarListEntry = Insert(calendar); 72 | } 73 | else 74 | { 75 | calendarListEntry = Update(calendar, calendarId); 76 | } 77 | 78 | return calendarListEntry; 79 | } 80 | 81 | /// Updates an existing calendar on the user's calendar list. 82 | /// 83 | /// 84 | public CalendarListEntry Update(CalendarListEntry calendar, string calendarId) 85 | { 86 | UpdateRequest updateRequest = calendarService.CalendarList.Update(calendar, calendarId); 87 | CalendarListEntry calendarListEntry = updateRequest.Execute(); 88 | 89 | return calendarListEntry; 90 | } 91 | 92 | /// Updates an existing calendar on the user's calendar list. This method supports patch semantics. 93 | /// 94 | /// 95 | public CalendarListEntry Patch(CalendarListEntry calendar, string calendarId) 96 | { 97 | PatchRequest patchRequest = calendarService.CalendarList.Patch(calendar, calendarId); 98 | CalendarListEntry calendarListEntry = patchRequest.Execute(); 99 | 100 | return calendarListEntry; 101 | } 102 | 103 | /// Removes a calendar from the user's calendar list. 104 | /// 105 | /// 106 | public string Delete(string calendarId) 107 | { 108 | DeleteRequest deleteRequest = calendarService.CalendarList.Delete(calendarId); 109 | string deleted = deleteRequest.Execute(); 110 | 111 | return deleted; 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Public Google Calendars 2 | Click one of the links below to integrate the calendar in your own. 3 | 4 | ## International 5 | - [Worlds](https://calendar.google.com/calendar/u/0?cid=ZjA0Z2Jhc29haGhwOWF2dDE0YnJnMnNtOGdAZ3JvdXAuY2FsZW5kYXIuZ29vZ2xlLmNvbQ) 6 | - [MSI](https://calendar.google.com/calendar/u/0?cid=bXV2Y2NxNzA1ZTljdnFocnBtYjB1NHU4c2NAZ3JvdXAuY2FsZW5kYXIuZ29vZ2xlLmNvbQ) 7 | - [First Stand](https://calendar.google.com/calendar/u/0?cid=OTBmYjMwY2I5MzJkOGUwNzUzYjAyODRlOWRlMjE0ODE2N2RlNzVjNjMxNGQzNzhmNDZlYTA5Yzk3MTgzMzQyZkBncm91cC5jYWxlbmRhci5nb29nbGUuY29t) 8 | - [TFT Esports](https://calendar.google.com/calendar/u/0?cid=MmRjYTA2M2I0ZGQ5NDI5Mjc4ZDZjNTg0MTY3M2ZhYTUzMWUzZTNlYTdmMTZhOTExMjQzOTIxYTc1NDU3YzRiNUBncm91cC5jYWxlbmRhci5nb29nbGUuY29t) 9 | 10 | ## America 11 | - [LLA](https://calendar.google.com/calendar/u/0?cid=MDBlOTllZWJmYTcxMzIwMDZlM2Y1MDJiY2E3NmZmNDU5OTU5NmU0NmRjZTAwM2Q3M2JlMjIwYmU3MzE4YTA4OEBncm91cC5jYWxlbmRhci5nb29nbGUuY29t) 12 | - [LTA Cross-Conference](https://calendar.google.com/calendar/u/0?cid=ZWYyNzJiNWRmZjk4ZWY2MjYxYTE5MDg5M2VjZjNhNjQzMWY4ZDQ5N2Y1ZDgxZThkYmE3OTQ1OGFkNDk5NTY2N0Bncm91cC5jYWxlbmRhci5nb29nbGUuY29t) 13 | - [Americas Challengers](https://calendar.google.com/calendar/u/0?cid=NzUxMGY4NWYxMDM4OTZkODM0NTUxNjRhZmIzZDc4NTA2NmJlNzUyNzJmMTA5Zjk1ZGUzYTBkNjE1NzE2ZWJlOUBncm91cC5jYWxlbmRhci5nb29nbGUuY29t) 14 | 15 | ### North America 16 | - [LCS](https://calendar.google.com/calendar/u/0?cid=M2g4ZXBiaGtrZms2OGJqajE2ZjNhOHVyZjhAZ3JvdXAuY2FsZW5kYXIuZ29vZ2xlLmNvbQ) 17 | - [NACL](https://calendar.google.com/calendar/u/0?cid=MzFkMTE5YTU1MDVlYjg1NzI2OGE2MTE5MmFhMGRmNTVhYjNmMTAzN2VjYmFlNDJkYWMzYzlkODViYzBmYmU5Y0Bncm91cC5jYWxlbmRhci5nb29nbGUuY29t) 18 | - [LTA North](https://calendar.google.com/calendar/u/0?cid=N2I5YzAyMTgwYzljN2NkZGYyOGIzZjFmYTliZmY4OTg0NWU0Mzg0ODcxODcwM2Q3MzdhZTg4YmY4OTg3YjRlNUBncm91cC5jYWxlbmRhci5nb29nbGUuY29t) 19 | - [North Regional League](https://calendar.google.com/calendar/u/0?cid=NWVjZDQ5MzY3ZWEyMTNlY2RhYTE1YzE0M2IzNzA2ZWVlYmRiODMwMDZjYzRmY2ZmNDhhZTdhNTQ3MTAwYTE2Y0Bncm91cC5jYWxlbmRhci5nb29nbGUuY29t) 20 | 21 | ### South America 22 | - [CBLOL](https://calendar.google.com/calendar/u/0?cid=NGl2azczcWs4MzdubWNuN3ZnaTZsMXZncG9AZ3JvdXAuY2FsZW5kYXIuZ29vZ2xlLmNvbQ) 23 | - [LTA South](https://calendar.google.com/calendar/u/0?cid=ODI4NTEwMGRkMmFlOThlODJkZjcxNTQ1MmRmMDMxNzliYjUwZjliNjkwN2RlNDE4NDNiNmZkNTlmODk1OTE2N0Bncm91cC5jYWxlbmRhci5nb29nbGUuY29t) 24 | - [South Regional League](https://calendar.google.com/calendar/u/0?cid=YjU4MmU0ZjVmYTY0NDViYjBiOWZlMDBjMmQyNzQyNGM5MzVjYTNjMGUyZWEzZGUwNTQwODY4MjI5NWIwYzFjY0Bncm91cC5jYWxlbmRhci5nb29nbGUuY29t) 25 | - [Circuito Desafiante](https://calendar.google.com/calendar/u/0?cid=ODc1MGE2MzQzODY2ZGMyNGQwYmY2MDhiNjI5YWYyNGZlMzdhMDM3NmZmZTQ2MWVlZTgyNzFjN2Y5ZTM5ZTUzMEBncm91cC5jYWxlbmRhci5nb29nbGUuY29t) 26 | 27 | ## Asia 28 | - [LCK](https://calendar.google.com/calendar/u/0?cid=aDRmbnA0aDJrZXR0aDRsaWpmbDYwbmZ0cmtAZ3JvdXAuY2FsZW5kYXIuZ29vZ2xlLmNvbQ) 29 | - [LPL](https://calendar.google.com/calendar/u/0?cid=b2Rza3BidDhscnVhdnF0bzBlajJoNGNscWtAZ3JvdXAuY2FsZW5kYXIuZ29vZ2xlLmNvbQ) 30 | - [LJL](https://calendar.google.com/calendar/u/0?cid=NzczMzUwMjVmNzM1YzM2MmMwYWRkNGNiODE3NmQ2M2JkNmE1OTEwZjE1ZDFlZGFlYTIzZWJlODcxMzI3NGNkZkBncm91cC5jYWxlbmRhci5nb29nbGUuY29t) 31 | - [PCS](https://calendar.google.com/calendar/u/0?cid=MzQyZDFmNzQxODk4OTI1NjcyOTkzNTlhMGIzNGIyYjdjOGY1MzBhNjJlNTBmMDFmMzVhZGQzYTQ2MzBiNGQ1MUBncm91cC5jYWxlbmRhci5nb29nbGUuY29t) 32 | - [VCS](https://calendar.google.com/calendar/u/0?cid=ZDdiYWJlZTMwMGM4YTgwY2ViZTFjNmQyYzQyMDA0YWQ3ZjBjOWE1MmNlMjhjYTVhZmY3ZWY2Y2U2MDcxN2QwM0Bncm91cC5jYWxlbmRhci5nb29nbGUuY29t) 33 | - [LCP](https://calendar.google.com/calendar/u/0?cid=NmU3OTc5NjM0Njk3NTZlZjUxYTljMDAyMjc1MGE1MDlkOTIxODRjODBlNTUxMDMyMTI2OTFlMDlhYTVmOTZiOEBncm91cC5jYWxlbmRhci5nb29nbGUuY29t) 34 | - [LCO](https://calendar.google.com/calendar/u/0?cid=NjEwM2I4YzZjNzIzZWM0Y2I1YWZlZjFhNzJkYjUwOGI2YWQzYmJiOGMyNjVjNjZjZTBlYjM2NjI3NTk5OTkzMEBncm91cC5jYWxlbmRhci5nb29nbGUuY29t) 35 | - [LCK Challengers](https://calendar.google.com/calendar/u/0?cid=NTUwNGQwM2FhMDEyNGMzOTg4MDFhOWM3OGJhNmMwOTY4MDlhNzNkMzQ1MDIwYTc5OWZjMGQyNWUyZGYzN2M3OEBncm91cC5jYWxlbmRhci5nb29nbGUuY29t) 36 | 37 | ## EMEA (Europe / Middle East / Africa) 38 | - [LEC](https://calendar.google.com/calendar/u/0?cid=aXAwMmdmOTk1MGxhaGxrcTM3MzhtanI2ZGtAZ3JvdXAuY2FsZW5kYXIuZ29vZ2xlLmNvbQ) 39 | - [NLC](https://calendar.google.com/calendar/u/0?cid=MjZlMWI2MTU1NDBkZTY4ZGVkY2QwOGEzMDAwYzE2OTcxZjZiMjc0Yzk3YWVhNTgwOTQ0MjAzYWM1MDM3ZmQyMkBncm91cC5jYWxlbmRhci5nb29nbGUuY29t) 40 | - [EMEA Masters](https://calendar.google.com/calendar/u/0?cid=djhxYmFqbmJ0M2R1b2Y1ODZpYWQ3MXBiYm9AZ3JvdXAuY2FsZW5kYXIuZ29vZ2xlLmNvbQ) 41 | - [TCL](https://calendar.google.com/calendar/u/0?cid=ZTRhNzVkZWIwNGNjNWQ4NjM5ZDM4ZmM0ZjhhMzlmOWQ2YjkwNDJlNWVmN2YyOWE5MmY4NmVlYzJjMDg4MGMxZUBncm91cC5jYWxlbmRhci5nb29nbGUuY29t) 42 | - [La Ligue Française](https://calendar.google.com/calendar/u/0?cid=NGhoZW85bWc2a2FvdmY5ZnNmcjFiNm5tNGdAZ3JvdXAuY2FsZW5kYXIuZ29vZ2xlLmNvbQ) 43 | - [Road of Legends](https://calendar.google.com/calendar/u/0?cid=NWU4NDU0MjgxZWUzNzdmYjk5ZTgyN2NhOWU4NTM2NTRkYzVlZmMxMGRkM2U3YmRkOWIxOGJmNmY0NjcwYmE2NkBncm91cC5jYWxlbmRhci5nb29nbGUuY29t) 44 | - [Esports Balkan League](https://calendar.google.com/calendar/u/0?cid=ODVkZTdhMzMzNThhMWIwZjRkZDE5ZjRlMWI2YTYzZjNmZTI2MWUyMDM4YzE1MGIxNjFlNTFlZmJhYzY5MTBlOEBncm91cC5jYWxlbmRhci5nb29nbGUuY29t) 45 | - [Liga Portuguesa](https://calendar.google.com/calendar/u/0?cid=ZGU5YzgyODFmY2NjOTVhZTM5MGNmMzMwMzNlMzQ3ODRiZjZlOTZkNmRjMjAzNmQyNDNmNTI3ZmQ5NDRmYTQwZUBncm91cC5jYWxlbmRhci5nb29nbGUuY29t) 46 | - [Hellenic Legends League](https://calendar.google.com/calendar/u/0?cid=NzEyN2M2Y2RlOGY5NjU5Y2I4YzQ3ZWExYjY1MDc1NTA0ODhhZGFlMjY0OGM2YTQwY2U3OGJkYWJjYjZkY2I1MkBncm91cC5jYWxlbmRhci5nb29nbGUuY29t) 47 | - [Hitpoint Masters](https://calendar.google.com/calendar/u/0?cid=ZWZjNmQyY2Q2M2VjZDg3ZGZmZjkyOTRkYmVlOWI1YmMxMDc0ZWVjY2YyNTg5NzNmOTQ5ZGM0N2I5NWZlNTlmZUBncm91cC5jYWxlbmRhci5nb29nbGUuY29t) 48 | - [LoL Italian Tournament](https://calendar.google.com/calendar/u/0?cid=ODA2OGIyOTFkMDljOGFkYTdlNzMyYTkzMGY1NzhhMWYzMjUxNWZjMGQ2NDFmZTZkZDRlYjU0OTYxM2M0NDY5OUBncm91cC5jYWxlbmRhci5nb29nbGUuY29t) 49 | - [Rift Legends](https://calendar.google.com/calendar/u/0?cid=NDU0YTBjZDRkMjFkZjY0MzY4M2UyY2VlZTZkNTAxYzNlOTE0NmIyNzM2OGQzNjRmZDliZDFmYjJlOTEyNGUyNkBncm91cC5jYWxlbmRhci5nb29nbGUuY29t) 50 | - [SuperLiga](https://calendar.google.com/calendar/u/0?cid=ZTBiN2Y5MjY3ZjNiYzUwMTljZmQ3ODM4Mjg1MzBhZTEwMjhhNmJiMmRjYjNjYWQ2Y2QyMTEwM2MwODliZWViMkBncm91cC5jYWxlbmRhci5nb29nbGUuY29t) 51 | - [Prime League](https://calendar.google.com/calendar/u/0?cid=NzYzMzE1YmQ1YTQ5YTIzYjlhYzU5MDBlZGQ0MWQ4YzY4YzVjOGYxNjcwNjMwMTgyZWZkMDIxZGQyZjI4NzQyYUBncm91cC5jYWxlbmRhci5nb29nbGUuY29t) 52 | - [Arabian League](https://calendar.google.com/calendar/u/0?cid=YjgxYTNkODk0ZmY3ODI1OTA5NmE3NzA2YjUyY2MyYzU1ODY2Zjc3NWRjOWExMDAxOTQzMThkNjYwMTExNWE0OEBncm91cC5jYWxlbmRhci5nb29nbGUuY29t) 53 | 54 | # Support 55 | Let [me know](https://github.com/ArnoutPullen/LolEsportsCalendar/issues/new?title=Feature%20Request:%20New%20Calendar) if you would like to see more calendars. 56 | 57 | ## Calendar not visible on iPhone 58 | - Check the [following link](https://calendar.google.com/calendar/u/0/syncselect) and resync the calendar. 59 | 60 | # References 61 | - https://lolesports.com/schedule 62 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # Credentials 7 | credentials.json 8 | appsecrets.json 9 | appsettings.Development.json 10 | docker.txt 11 | 12 | # User-specific files 13 | *.rsuser 14 | *.suo 15 | *.user 16 | *.userosscache 17 | *.sln.docstates 18 | 19 | # User-specific files (MonoDevelop/Xamarin Studio) 20 | *.userprefs 21 | 22 | # Build results 23 | [Dd]ebug/ 24 | [Dd]ebugPublic/ 25 | [Rr]elease/ 26 | [Rr]eleases/ 27 | x64/ 28 | x86/ 29 | [Aa][Rr][Mm]/ 30 | [Aa][Rr][Mm]64/ 31 | bld/ 32 | [Bb]in/ 33 | [Oo]bj/ 34 | [Ll]og/ 35 | 36 | # Visual Studio 2015/2017 cache/options directory 37 | .vs/ 38 | # Uncomment if you have tasks that create the project's static files in wwwroot 39 | #wwwroot/ 40 | 41 | # Visual Studio 2017 auto generated files 42 | Generated\ Files/ 43 | 44 | # MSTest test Results 45 | [Tt]est[Rr]esult*/ 46 | [Bb]uild[Ll]og.* 47 | 48 | # NUNIT 49 | *.VisualState.xml 50 | TestResult.xml 51 | 52 | # Build Results of an ATL Project 53 | [Dd]ebugPS/ 54 | [Rr]eleasePS/ 55 | dlldata.c 56 | 57 | # Benchmark Results 58 | BenchmarkDotNet.Artifacts/ 59 | 60 | # .NET Core 61 | project.lock.json 62 | project.fragment.lock.json 63 | artifacts/ 64 | 65 | # StyleCop 66 | StyleCopReport.xml 67 | 68 | # Files built by Visual Studio 69 | *_i.c 70 | *_p.c 71 | *_h.h 72 | *.ilk 73 | *.meta 74 | *.obj 75 | *.iobj 76 | *.pch 77 | *.pdb 78 | *.ipdb 79 | *.pgc 80 | *.pgd 81 | *.rsp 82 | *.sbr 83 | *.tlb 84 | *.tli 85 | *.tlh 86 | *.tmp 87 | *.tmp_proj 88 | *_wpftmp.csproj 89 | *.log 90 | *.vspscc 91 | *.vssscc 92 | .builds 93 | *.pidb 94 | *.svclog 95 | *.scc 96 | 97 | # Chutzpah Test files 98 | _Chutzpah* 99 | 100 | # Visual C++ cache files 101 | ipch/ 102 | *.aps 103 | *.ncb 104 | *.opendb 105 | *.opensdf 106 | *.sdf 107 | *.cachefile 108 | *.VC.db 109 | *.VC.VC.opendb 110 | 111 | # Visual Studio profiler 112 | *.psess 113 | *.vsp 114 | *.vspx 115 | *.sap 116 | 117 | # Visual Studio Trace Files 118 | *.e2e 119 | 120 | # TFS 2012 Local Workspace 121 | $tf/ 122 | 123 | # Guidance Automation Toolkit 124 | *.gpState 125 | 126 | # ReSharper is a .NET coding add-in 127 | _ReSharper*/ 128 | *.[Rr]e[Ss]harper 129 | *.DotSettings.user 130 | 131 | # JustCode is a .NET coding add-in 132 | .JustCode 133 | 134 | # TeamCity is a build add-in 135 | _TeamCity* 136 | 137 | # DotCover is a Code Coverage Tool 138 | *.dotCover 139 | 140 | # AxoCover is a Code Coverage Tool 141 | .axoCover/* 142 | !.axoCover/settings.json 143 | 144 | # Visual Studio code coverage results 145 | *.coverage 146 | *.coveragexml 147 | 148 | # NCrunch 149 | _NCrunch_* 150 | .*crunch*.local.xml 151 | nCrunchTemp_* 152 | 153 | # MightyMoose 154 | *.mm.* 155 | AutoTest.Net/ 156 | 157 | # Web workbench (sass) 158 | .sass-cache/ 159 | 160 | # Installshield output folder 161 | [Ee]xpress/ 162 | 163 | # DocProject is a documentation generator add-in 164 | DocProject/buildhelp/ 165 | DocProject/Help/*.HxT 166 | DocProject/Help/*.HxC 167 | DocProject/Help/*.hhc 168 | DocProject/Help/*.hhk 169 | DocProject/Help/*.hhp 170 | DocProject/Help/Html2 171 | DocProject/Help/html 172 | 173 | # Click-Once directory 174 | publish/ 175 | 176 | # Publish Web Output 177 | *.[Pp]ublish.xml 178 | *.azurePubxml 179 | # Note: Comment the next line if you want to checkin your web deploy settings, 180 | # but database connection strings (with potential passwords) will be unencrypted 181 | *.pubxml 182 | *.publishproj 183 | 184 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 185 | # checkin your Azure Web App publish settings, but sensitive information contained 186 | # in these scripts will be unencrypted 187 | PublishScripts/ 188 | 189 | # NuGet Packages 190 | *.nupkg 191 | # The packages folder can be ignored because of Package Restore 192 | **/[Pp]ackages/* 193 | # except build/, which is used as an MSBuild target. 194 | !**/[Pp]ackages/build/ 195 | # Uncomment if necessary however generally it will be regenerated when needed 196 | #!**/[Pp]ackages/repositories.config 197 | # NuGet v3's project.json files produces more ignorable files 198 | *.nuget.props 199 | *.nuget.targets 200 | 201 | # Microsoft Azure Build Output 202 | csx/ 203 | *.build.csdef 204 | 205 | # Microsoft Azure Emulator 206 | ecf/ 207 | rcf/ 208 | 209 | # Windows Store app package directories and files 210 | AppPackages/ 211 | BundleArtifacts/ 212 | Package.StoreAssociation.xml 213 | _pkginfo.txt 214 | *.appx 215 | 216 | # Visual Studio cache files 217 | # files ending in .cache can be ignored 218 | *.[Cc]ache 219 | # but keep track of directories ending in .cache 220 | !?*.[Cc]ache/ 221 | 222 | # Others 223 | ClientBin/ 224 | ~$* 225 | *~ 226 | *.dbmdl 227 | *.dbproj.schemaview 228 | *.jfm 229 | *.pfx 230 | *.publishsettings 231 | orleans.codegen.cs 232 | 233 | # Including strong name files can present a security risk 234 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 235 | #*.snk 236 | 237 | # Since there are multiple workflows, uncomment next line to ignore bower_components 238 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 239 | #bower_components/ 240 | 241 | # RIA/Silverlight projects 242 | Generated_Code/ 243 | 244 | # Backup & report files from converting an old project file 245 | # to a newer Visual Studio version. Backup files are not needed, 246 | # because we have git ;-) 247 | _UpgradeReport_Files/ 248 | Backup*/ 249 | UpgradeLog*.XML 250 | UpgradeLog*.htm 251 | ServiceFabricBackup/ 252 | *.rptproj.bak 253 | 254 | # SQL Server files 255 | *.mdf 256 | *.ldf 257 | *.ndf 258 | 259 | # Business Intelligence projects 260 | *.rdl.data 261 | *.bim.layout 262 | *.bim_*.settings 263 | *.rptproj.rsuser 264 | *- Backup*.rdl 265 | 266 | # Microsoft Fakes 267 | FakesAssemblies/ 268 | 269 | # GhostDoc plugin setting file 270 | *.GhostDoc.xml 271 | 272 | # Node.js Tools for Visual Studio 273 | .ntvs_analysis.dat 274 | node_modules/ 275 | 276 | # Visual Studio 6 build log 277 | *.plg 278 | 279 | # Visual Studio 6 workspace options file 280 | *.opt 281 | 282 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 283 | *.vbw 284 | 285 | # Visual Studio LightSwitch build output 286 | **/*.HTMLClient/GeneratedArtifacts 287 | **/*.DesktopClient/GeneratedArtifacts 288 | **/*.DesktopClient/ModelManifest.xml 289 | **/*.Server/GeneratedArtifacts 290 | **/*.Server/ModelManifest.xml 291 | _Pvt_Extensions 292 | 293 | # Paket dependency manager 294 | .paket/paket.exe 295 | paket-files/ 296 | 297 | # FAKE - F# Make 298 | .fake/ 299 | 300 | # JetBrains Rider 301 | .idea/ 302 | *.sln.iml 303 | 304 | # CodeRush personal settings 305 | .cr/personal 306 | 307 | # Python Tools for Visual Studio (PTVS) 308 | __pycache__/ 309 | *.pyc 310 | 311 | # Cake - Uncomment if you are using it 312 | # tools/** 313 | # !tools/packages.config 314 | 315 | # Tabs Studio 316 | *.tss 317 | 318 | # Telerik's JustMock configuration file 319 | *.jmconfig 320 | 321 | # BizTalk build output 322 | *.btp.cs 323 | *.btm.cs 324 | *.odx.cs 325 | *.xsd.cs 326 | 327 | # OpenCover UI analysis results 328 | OpenCover/ 329 | 330 | # Azure Stream Analytics local run output 331 | ASALocalRun/ 332 | 333 | # MSBuild Binary and Structured Log 334 | *.binlog 335 | 336 | # NVidia Nsight GPU debugger configuration file 337 | *.nvuser 338 | 339 | # MFractors (Xamarin productivity tool) working folder 340 | .mfractor/ 341 | 342 | # Local History for Visual Studio 343 | .localhistory/ 344 | 345 | # BeatPulse healthcheck temp database 346 | healthchecksdb 347 | /LolEsportsCalendar/token.json/Google.Apis.Auth.OAuth2.Responses.TokenResponse-user 348 | -------------------------------------------------------------------------------- /LolEsportsCalendar/Services/LolEsportsService.cs: -------------------------------------------------------------------------------- 1 | using Google; 2 | using Google.Apis.Calendar.v3.Data; 3 | using GoogleCalendarApiClient.Services; 4 | using LolEsportsApiClient; 5 | using LolEsportsApiClient.Models; 6 | using LolEsportsApiClient.Options; 7 | using Microsoft.Extensions.Logging; 8 | using Microsoft.Extensions.Options; 9 | using System; 10 | using System.Collections.Generic; 11 | using System.Threading; 12 | using System.Threading.Tasks; 13 | 14 | namespace LolEsportsCalendar.Services; 15 | 16 | public class LolEsportsService( 17 | GoogleCalendarService googleCalendarService, 18 | LolEsportsClient lolEsportsClient, 19 | EventsService eventsService, 20 | CalendarsService calendarsService, 21 | ILogger logger, 22 | IOptions options 23 | ) 24 | { 25 | private int _rateLimitExceededCount = 0; 26 | 27 | public async Task ImportEvents(CancellationToken cancellationToken = default) 28 | { 29 | string[]? leagueNames = options.Value.Leagues; 30 | 31 | if (leagueNames != null) 32 | { 33 | foreach (var leagueName in leagueNames) 34 | { 35 | Calendar? calendar = await FindOrCreateCalendarByLeagueName(leagueName, cancellationToken); 36 | 37 | if (calendar != null) 38 | { 39 | League? league = await lolEsportsClient.GetLeagueByName(leagueName, cancellationToken); 40 | 41 | if (league == null) 42 | { 43 | logger.LogWarning("Couldn't find league with name {LeagueName}", leagueName); 44 | } 45 | else 46 | { 47 | // Import events for calendar 48 | await ImportEventsForLeagueAsync(league, calendar, cancellationToken: cancellationToken); 49 | } 50 | } 51 | } 52 | } 53 | else 54 | { 55 | await ImportEventsForAllCalendarsAsync(cancellationToken); 56 | } 57 | 58 | logger.LogInformation("All events imported"); 59 | } 60 | 61 | public async Task ImportEventsForAllCalendarsAsync(CancellationToken cancellationToken = default) 62 | { 63 | try 64 | { 65 | List leagues = await lolEsportsClient.GetLeaguesAsync(cancellationToken); 66 | 67 | foreach (League league in leagues) 68 | { 69 | Calendar? calendar = await FindOrCreateCalendarByLeagueName(league.Name, cancellationToken); 70 | 71 | if (calendar != null) 72 | { 73 | // Import events for calendar 74 | await ImportEventsForLeagueAsync(league, calendar, cancellationToken: cancellationToken); 75 | 76 | // Wait 1 sec 77 | await Task.Delay(60, cancellationToken); 78 | } 79 | 80 | } 81 | } 82 | catch (Exception exception) 83 | { 84 | logger.LogError(exception, "Error while importing events for all calendars"); 85 | } 86 | } 87 | 88 | public async Task ImportEventsForLeagueAsync(League league, Calendar calendar, string? page = null, CancellationToken cancellationToken = default) 89 | { 90 | try 91 | { 92 | LolEsportsScheduleResponseData? data = null; 93 | 94 | do 95 | { 96 | // Get scheduled events of league 97 | data = await lolEsportsClient.GetScheduleByLeagueAsync(league, page, cancellationToken); 98 | 99 | foreach (EsportEvent esportEvent in data?.Schedule.Events ?? []) 100 | { 101 | if (null == esportEvent.Match.Id) 102 | { 103 | logger.LogError("Error esport event.match.id null"); 104 | continue; 105 | } 106 | // Convert LeagueEvent to GoogleEvent 107 | Event googleEvent = GoogleCalendarService.ConvertEsportEventToGoogleEvent(esportEvent); 108 | 109 | // Insert or Update GoogleEvent 110 | eventsService.InsertOrUpdate(googleEvent, calendar, googleEvent.Id); // TODO 111 | } 112 | 113 | page = data?.Schedule.Pages?.Newer; 114 | } while (data?.Schedule.Pages?.Newer != null); 115 | } 116 | catch (GoogleApiException exception) 117 | { 118 | // :( Google can't handle all requests 119 | // https://developers.google.com/calendar/api/guides/quota 120 | // https://stackoverflow.com/a/40990761/5828267 121 | if (exception.Error.Code == 403 && exception.Error.Message == "Rate Limit Exceeded") 122 | { 123 | _rateLimitExceededCount++; 124 | 125 | if (_rateLimitExceededCount < 8) 126 | { 127 | // Wait 128 | await Task.Delay(60 * _rateLimitExceededCount, cancellationToken); 129 | 130 | // Retry 131 | await ImportEventsForLeagueAsync(league, calendar, cancellationToken: cancellationToken); 132 | } 133 | } 134 | logger.LogError(exception, "Error while importing events for leauge {LeagueName}", league.Name); 135 | } 136 | catch (Exception exception) 137 | { 138 | logger.LogError(exception, "Error while importing events for leauge {LeagueName}", league.Name); 139 | } 140 | 141 | logger.LogInformation("Events imported for league {LeagueName}", league.Name); 142 | } 143 | 144 | public async Task FindOrCreateCalendarByLeagueName(string leagueName, CancellationToken cancellationToken = default) 145 | { 146 | string? calendarId = null; 147 | 148 | // Get calendars 149 | var calendars = googleCalendarService.GetCalendarLookup(); 150 | 151 | // Get league 152 | League? league = await lolEsportsClient.GetLeagueByName(leagueName, cancellationToken); 153 | 154 | if (league == null) 155 | { 156 | logger.LogWarning("Couldn't find league with name {LeagueName}", leagueName); 157 | return null; 158 | } 159 | 160 | foreach (var c in calendars) 161 | { 162 | if (c.Key == league.Name) 163 | { 164 | calendarId = c.Value; 165 | } 166 | else 167 | if (c.Key == league.Slug) 168 | { 169 | calendarId = c.Value; 170 | } 171 | } 172 | 173 | if (calendarId == null) 174 | { 175 | // Creat new calendar 176 | logger.LogInformation("Creating new calendar {LeagueName}", league.Name); 177 | Calendar newCalendar = ConvertLeagueToCalendar(league); 178 | Calendar calendar = calendarsService.Insert(newCalendar); 179 | lolEsportsClient.ClearLeaguesCache(); 180 | 181 | return calendar; 182 | } 183 | 184 | return calendarsService.Get(calendarId); 185 | } 186 | 187 | public static Calendar ConvertLeagueToCalendar(League league) 188 | { 189 | Calendar calendar = new() 190 | { 191 | Summary = league.Name, 192 | Description = league.Name + " / " + league.Region, 193 | // ETag = "Test", 194 | // Kind = "Test", 195 | // Location = "Test", 196 | // TimeZone = "Europe/Amsterdam" 197 | }; 198 | 199 | return calendar; 200 | } 201 | } 202 | -------------------------------------------------------------------------------- /GoogleCalendarApiClient/Services/EventsService.cs: -------------------------------------------------------------------------------- 1 | using Google; 2 | using Google.Apis.Calendar.v3; 3 | using Google.Apis.Calendar.v3.Data; 4 | using Microsoft.Extensions.Logging; 5 | using System; 6 | using System.Reflection; 7 | 8 | namespace GoogleCalendarApiClient.Services; 9 | 10 | public class EventsService(CalendarService calendarService, ILogger logger) 11 | { 12 | /// Returns events on the specified calendar. 13 | /// 14 | /// 15 | public Events List(string calendarId) 16 | { 17 | EventsResource.ListRequest listRequest = calendarService.Events.List(calendarId); 18 | return listRequest.Execute(); 19 | } 20 | 21 | /// Returns an event. 22 | /// 23 | /// 24 | public Event? Get(string calendarId, string eventId) 25 | { 26 | Event? _event = null; 27 | 28 | try 29 | { 30 | EventsResource.GetRequest getRequest = calendarService.Events.Get(calendarId, eventId); 31 | _event = getRequest.Execute(); 32 | } 33 | catch (GoogleApiException exception) 34 | { 35 | if (exception.Error.Code == 404) 36 | { 37 | logger.LogDebug(exception, "Couldn't find Event with id {EventId}", eventId); 38 | } 39 | else 40 | { 41 | logger.LogError(exception, "Error while getting Event with id {EventId}", eventId); 42 | } 43 | } 44 | catch (Exception exception) 45 | { 46 | logger.LogError(exception, "Error while getting Event with id {EventId}", eventId); 47 | } 48 | 49 | return _event; 50 | } 51 | 52 | /// Creates an event. 53 | /// 54 | /// 55 | public Event Insert(Event _event, Calendar calendar) 56 | { 57 | EventsResource.InsertRequest insertRequest = calendarService.Events.Insert(_event, calendar.Id); 58 | return insertRequest.Execute(); 59 | } 60 | 61 | public Event InsertOrUpdate(Event _event, Calendar calendar, string eventId) 62 | { 63 | Event? existing = Get(calendar.Id, eventId); 64 | 65 | if (existing == null) 66 | { 67 | logger.LogInformation("Inserting Event {EventSummary} ({EventId}) in calendar {CalendarSummary}", _event.Summary, eventId, calendar.Summary); 68 | return Insert(_event, calendar); 69 | } 70 | 71 | // Compare events, only update when data changed 72 | bool equals = Compare(_event, existing); 73 | 74 | if (!equals) 75 | { 76 | logger.LogInformation("Updating Event {EventSummary} ({EventId}) in calendar {CalendarSummary}", _event.Summary, eventId, calendar.Summary); 77 | return Update(_event, calendar, eventId); 78 | } 79 | 80 | // TODO: Show league name 81 | logger.LogDebug("Event unchanged while trying to InsertOrUpdate Event {EventSummary} ({EventId}) in calendar {CalendarSummary}", _event.Summary, eventId, calendar.Summary); 82 | 83 | return existing; 84 | } 85 | 86 | public bool Compare(object expectedObject, object actualObject) 87 | { 88 | Type expectedObjectType = expectedObject.GetType(); 89 | Type actualObjectType = actualObject.GetType(); 90 | bool equals = true; 91 | 92 | foreach (PropertyInfo expectedProperty in expectedObjectType.GetProperties()) 93 | { 94 | object? expectedPropertyValue = expectedProperty.GetValue(expectedObject); 95 | object? actualPropertyValue = actualObjectType.GetProperty(expectedProperty.Name)?.GetValue(actualObject); 96 | 97 | // Skip if both null 98 | if (expectedPropertyValue == null && actualPropertyValue == null) 99 | { 100 | continue; 101 | } 102 | 103 | // Skip if string not changed 104 | if (expectedPropertyValue is string && actualPropertyValue is string) 105 | { 106 | bool stringEquals = string.Equals(expectedPropertyValue, actualPropertyValue); 107 | 108 | if (stringEquals == false) 109 | { 110 | equals = false; 111 | break; 112 | } 113 | 114 | continue; 115 | } 116 | 117 | // Skip if value not changed 118 | if (expectedPropertyValue == actualPropertyValue) 119 | { 120 | continue; 121 | } 122 | 123 | // Skip if expected value is null 124 | if (expectedPropertyValue == null) 125 | { 126 | continue; 127 | } 128 | 129 | if (expectedPropertyValue is DateTime expectedDateTime) 130 | { 131 | int result = expectedDateTime.CompareTo(actualPropertyValue); 132 | 133 | if (result != 0) 134 | { 135 | equals = false; 136 | break; 137 | } 138 | 139 | continue; 140 | } 141 | 142 | if (expectedPropertyValue is EventDateTime expectedEventDateTime) 143 | { 144 | EventDateTime? actualEventDateTime = (EventDateTime?)actualPropertyValue; 145 | if (actualEventDateTime == null) { 146 | equals = false; 147 | break; 148 | } 149 | DateTimeOffset? actualDateTime = actualEventDateTime?.DateTimeDateTimeOffset; 150 | if (actualDateTime == null) { 151 | equals = false; 152 | break; 153 | } 154 | int? result = expectedEventDateTime?.DateTimeDateTimeOffset?.CompareTo((DateTimeOffset)actualDateTime); 155 | 156 | if (result != 0) 157 | { 158 | equals = false; 159 | break; 160 | } 161 | 162 | continue; 163 | } 164 | 165 | logger.LogDebug("{ExpectedPropertyName} Not Equals {ExpectedPropertyValue} != {ActualPropertyValue}", expectedProperty.Name, expectedPropertyValue, actualPropertyValue); 166 | } 167 | 168 | return equals; 169 | } 170 | 171 | /// Updates an event. 172 | /// 173 | /// 174 | public Event Update(Event _event, Calendar calendar, string eventId) 175 | { 176 | EventsResource.UpdateRequest updateRequest = calendarService.Events.Update(_event, calendar.Id, eventId); 177 | return updateRequest.Execute(); 178 | } 179 | 180 | /// Imports an event. This operation is used to add a private copy of an existing event to a calendar. 181 | /// 182 | /// 183 | public Event Import(Event _event, Calendar calendar) 184 | { 185 | EventsResource.ImportRequest importRequest = calendarService.Events.Import(_event, calendar.Id); 186 | return importRequest.Execute(); 187 | } 188 | 189 | /// Deletes an event. 190 | /// 191 | /// 192 | public string Delete(Calendar calendar, Event _event) 193 | { 194 | EventsResource.DeleteRequest deleteRequest = calendarService.Events.Delete(calendar.Id, _event.Id); 195 | return deleteRequest.Execute(); 196 | } 197 | } 198 | --------------------------------------------------------------------------------