Add departure date (midnight) for arr/dep trains
This commit is contained in:
parent
a9ade801ac
commit
4b4e04fb75
2 changed files with 20 additions and 0 deletions
|
@ -33,6 +33,7 @@ namespace InfoferScraper.Models.Station {
|
||||||
/// Arrivals -> Departure station; Departures -> Destination station
|
/// Arrivals -> Departure station; Departures -> Destination station
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Terminus { get; }
|
public string Terminus { get; }
|
||||||
|
public DateTimeOffset DepartureDate { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IStationStatus : IStatus {
|
public interface IStationStatus : IStatus {
|
||||||
|
@ -96,6 +97,7 @@ namespace InfoferScraper.Models.Station {
|
||||||
public string Rank { get; internal set; } = "";
|
public string Rank { get; internal set; } = "";
|
||||||
public IReadOnlyList<string> Route => _modifyableRoute.AsReadOnly();
|
public IReadOnlyList<string> Route => _modifyableRoute.AsReadOnly();
|
||||||
public string Terminus { get; internal set; } = "";
|
public string Terminus { get; internal set; } = "";
|
||||||
|
public DateTimeOffset DepartureDate { get; internal set; }
|
||||||
|
|
||||||
internal void AddRouteStation(string station) => _modifyableRoute.Add(station);
|
internal void AddRouteStation(string station) => _modifyableRoute.Add(station);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,8 @@ namespace InfoferScraper.Scrapers {
|
||||||
);
|
);
|
||||||
|
|
||||||
private static readonly Regex PlatformRegex = new(@"^linia\s([A-Za-z0-9]+)$");
|
private static readonly Regex PlatformRegex = new(@"^linia\s([A-Za-z0-9]+)$");
|
||||||
|
|
||||||
|
private static readonly Regex TrainUrlDateRegex = new(@"Date=([0-9]{2}).([0-9]{2}).([0-9]{4})");
|
||||||
|
|
||||||
private static readonly DateTimeZone BucharestTz = DateTimeZoneProviders.Tzdb["Europe/Bucharest"];
|
private static readonly DateTimeZone BucharestTz = DateTimeZoneProviders.Tzdb["Europe/Bucharest"];
|
||||||
|
|
||||||
|
@ -140,6 +142,22 @@ namespace InfoferScraper.Scrapers {
|
||||||
.QuerySelector(":scope > a")!
|
.QuerySelector(":scope > a")!
|
||||||
.Text()
|
.Text()
|
||||||
.WithCollapsedSpaces();
|
.WithCollapsedSpaces();
|
||||||
|
var trainUri = new Uri(
|
||||||
|
"http://localhost" + trainDiv
|
||||||
|
.QuerySelectorAll(":scope > div > div > div")[1]
|
||||||
|
.QuerySelector(":scope > a")!
|
||||||
|
.GetAttribute("href")!
|
||||||
|
);
|
||||||
|
var (trainDepDay, (trainDepMonth, (trainDepYear, _))) = TrainUrlDateRegex
|
||||||
|
.Match(trainUri.Query)
|
||||||
|
.Groups
|
||||||
|
.Values
|
||||||
|
.Skip(1)
|
||||||
|
.Select(g => int.Parse(g.Value));
|
||||||
|
arrDep.ModifyableTrain.DepartureDate = BucharestTz
|
||||||
|
.AtStartOfDay(new(trainDepYear, trainDepMonth, trainDepDay))
|
||||||
|
.ToDateTimeOffset()
|
||||||
|
.ToUniversalTime();
|
||||||
arrDep.ModifyableTrain.Terminus = destDiv
|
arrDep.ModifyableTrain.Terminus = destDiv
|
||||||
.QuerySelectorAll(":scope > div > div > div")[1]
|
.QuerySelectorAll(":scope > div > div > div")[1]
|
||||||
.Text()
|
.Text()
|
||||||
|
|
Loading…
Add table
Reference in a new issue