diff --git a/AacpsBusAlert.sln b/AacpsBusAlert.sln new file mode 100644 index 0000000..428a975 --- /dev/null +++ b/AacpsBusAlert.sln @@ -0,0 +1,37 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31903.59 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BinaryDad.AacpsBusAlert.Worker", "BinaryDad.AacpsBusAlert.Worker\BinaryDad.AacpsBusAlert.Worker.csproj", "{A11DB85E-ECAC-4CE7-866F-245BB8A3F4D0}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BinaryDad.AacpsBusAlert", "BinaryDad.AacpsBusAlert\BinaryDad.AacpsBusAlert.csproj", "{A5478ED8-55A1-40BB-B1DC-24EDF36E5B1A}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BinaryDad.AacpsBusAlert.Services", "BinaryDad.AacpsBusAlert.Services\BinaryDad.AacpsBusAlert.Services.csproj", "{3707126F-FE2F-4733-9702-1822AC05AABD}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {A11DB85E-ECAC-4CE7-866F-245BB8A3F4D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A11DB85E-ECAC-4CE7-866F-245BB8A3F4D0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A11DB85E-ECAC-4CE7-866F-245BB8A3F4D0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A11DB85E-ECAC-4CE7-866F-245BB8A3F4D0}.Release|Any CPU.Build.0 = Release|Any CPU + {A5478ED8-55A1-40BB-B1DC-24EDF36E5B1A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A5478ED8-55A1-40BB-B1DC-24EDF36E5B1A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A5478ED8-55A1-40BB-B1DC-24EDF36E5B1A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A5478ED8-55A1-40BB-B1DC-24EDF36E5B1A}.Release|Any CPU.Build.0 = Release|Any CPU + {3707126F-FE2F-4733-9702-1822AC05AABD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3707126F-FE2F-4733-9702-1822AC05AABD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3707126F-FE2F-4733-9702-1822AC05AABD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3707126F-FE2F-4733-9702-1822AC05AABD}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {933518CD-A34E-4096-AED4-BB5CD7D44F86} + EndGlobalSection +EndGlobal diff --git a/BinaryDad.AacpsBusAlert.Services/BinaryDad.AacpsBusAlert.Services.csproj b/BinaryDad.AacpsBusAlert.Services/BinaryDad.AacpsBusAlert.Services.csproj new file mode 100644 index 0000000..2703565 --- /dev/null +++ b/BinaryDad.AacpsBusAlert.Services/BinaryDad.AacpsBusAlert.Services.csproj @@ -0,0 +1,19 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + diff --git a/BinaryDad.AacpsBusAlert.Services/BusRouteService.cs b/BinaryDad.AacpsBusAlert.Services/BusRouteService.cs new file mode 100644 index 0000000..2e8b818 --- /dev/null +++ b/BinaryDad.AacpsBusAlert.Services/BusRouteService.cs @@ -0,0 +1,45 @@ +using BinaryDad.Extensions; +using Newtonsoft.Json; +using System.Text.RegularExpressions; + +namespace BinaryDad.AacpsBusAlert.Services +{ + public class BusRouteService + { + private readonly HttpClient httpClient; + + public BusRouteService(IHttpClientFactory httpClientFactory) + { + httpClient = httpClientFactory.CreateClient(); + } + + public async Task> GetBusRoutesAsync() + { + var url = "https://busstops.aacps.org/public/BusRouteIssues.aspx"; + var content = await httpClient.GetStringAsync(url); + + var dataArrayMatch = Regex.Match(content, "var dataArray \\= (.*)\\;"); + + if (dataArrayMatch.Success && dataArrayMatch.Groups.Count == 2) + { + var dataArray = dataArrayMatch.Groups[1].Value; + + var parsedArray = JsonConvert.DeserializeObject(dataArray); + + return parsedArray + .Select(r => new BusRoute + { + BusNumber = r[0].To(), + SubBusNumber = r[1].To(), + Schools = r[2], + Schedules = r[3], + Impact = r[4] + }) + .ToList(); + } + + throw new ApplicationException("Unable to parse bus route page"); + + } + } +} \ No newline at end of file diff --git a/BinaryDad.AacpsBusAlert.Worker/BinaryDad.AacpsBusAlert.Worker.csproj b/BinaryDad.AacpsBusAlert.Worker/BinaryDad.AacpsBusAlert.Worker.csproj new file mode 100644 index 0000000..8b580ae --- /dev/null +++ b/BinaryDad.AacpsBusAlert.Worker/BinaryDad.AacpsBusAlert.Worker.csproj @@ -0,0 +1,19 @@ + + + + Exe + net6.0 + enable + enable + + + + + + + + + + + + diff --git a/BinaryDad.AacpsBusAlert.Worker/Program.cs b/BinaryDad.AacpsBusAlert.Worker/Program.cs new file mode 100644 index 0000000..f447c97 --- /dev/null +++ b/BinaryDad.AacpsBusAlert.Worker/Program.cs @@ -0,0 +1,17 @@ +using BinaryDad.AacpsBusAlert.Services; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; + +var host = Host.CreateDefaultBuilder(args) + .ConfigureServices(services => + { + services.AddTransient(); + services.AddHttpClient(); + }) + .Build(); + +var busRouteService = host.Services.GetService(); + +var routes = await busRouteService.GetBusRoutesAsync(); + +Console.ReadLine(); \ No newline at end of file diff --git a/BinaryDad.AacpsBusAlert/BinaryDad.AacpsBusAlert.csproj b/BinaryDad.AacpsBusAlert/BinaryDad.AacpsBusAlert.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/BinaryDad.AacpsBusAlert/BinaryDad.AacpsBusAlert.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/BinaryDad.AacpsBusAlert/BusRoute.cs b/BinaryDad.AacpsBusAlert/BusRoute.cs new file mode 100644 index 0000000..10ba8c3 --- /dev/null +++ b/BinaryDad.AacpsBusAlert/BusRoute.cs @@ -0,0 +1,11 @@ +namespace BinaryDad.AacpsBusAlert +{ + public class BusRoute + { + public int BusNumber { get; set; } + public int SubBusNumber { get; set; } + public string Schools { get; set; } + public string Schedules { get; set; } + public string Impact { get; set; } + } +} \ No newline at end of file