Skip to content

Commit

Permalink
routes update
Browse files Browse the repository at this point in the history
  • Loading branch information
tomcoombs2000 committed Oct 20, 2024
1 parent 75619d7 commit b06357d
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions Features/Routes/Services/FlightAwareRouteService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace ZmaReference.Features.Routes.Services;

public partial class FlightAwareRouteService(IHttpClientFactory httpClientFactory, IOptionsMonitor<AppSettings> appSettings, IMemoryCache cache)
public partial class FlightAwareRouteService(IHttpClientFactory httpClientFactory, IOptionsMonitor<AppSettings> appSettings, IMemoryCache cache, ILogger<FlightAwareRouteService> logger)
{
public async Task<AirportPairRouteSummary> FetchRoutesAsync(string departureIcao, string arrivalIcao)
{
Expand All @@ -18,6 +18,7 @@ public async Task<AirportPairRouteSummary> FetchRoutesAsync(string departureIcao
}

// If not, fetch result from FlightAware
var url = MakeUrl(departureIcao, arrivalIcao);
try
{
// Setup return object
Expand All @@ -26,7 +27,7 @@ public async Task<AirportPairRouteSummary> FetchRoutesAsync(string departureIcao
// Open FlightAware IFR routing page
var client = httpClientFactory.CreateClient();
client.DefaultRequestHeaders.UserAgent.TryParseAdd("Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:123.0) Gecko/20100101 Firefox/123.0");
await using var stream = await client.GetStreamAsync(MakeUrl(departureIcao, arrivalIcao));
await using var stream = await client.GetStreamAsync(url);
var parser = new HtmlParser();
using var document = await parser.ParseDocumentAsync(stream);

Expand Down Expand Up @@ -101,11 +102,12 @@ public async Task<AirportPairRouteSummary> FetchRoutesAsync(string departureIcao
}
catch (HttpRequestException e)
{
logger.LogError("Error fetching FlightAware url {url}: {error}", url, e);
throw e;
}
}

private string MakeUrl(string departureIcao, string arrivalIcao)
public string MakeUrl(string departureIcao, string arrivalIcao)
{
return appSettings.CurrentValue.Urls.FlightAwareIfrRouteBase + "origin=" + departureIcao + "&destination=" + arrivalIcao;
}
Expand Down

0 comments on commit b06357d

Please sign in to comment.