36 lines
892 B
Go
36 lines
892 B
Go
package parser
|
|||
|
|
|
||
|
|
import (
|
||
|
|
"errors"
|
||
|
|
"time"
|
||
|
|
)
|
||
|
|
|
||
|
|
const (
|
||
|
|
FlopRegex = `(?m)^\((?P<flop>\w{3})-.*`
|
||
|
|
DestinationRegex = `(?P<dest>[A-Z]+)(?P<time>\d{0,4})?`
|
||
|
|
DOFRegex = `(?P<dof>\w+)/(?P<time>\d{6})`
|
||
|
|
TypeArrival = "ARR"
|
||
|
|
)
|
||
|
|
|
||
|
|
func parseArr(telegram *Telegram, data string) {
|
||
|
|
values := getFlopValues(data)
|
||
|
|
l := len(values)
|
||
|
|
if l < 4 {
|
||
|
|
telegram.ParseErrors = append(telegram.ParseErrors, errors.New("arrival data less than 4 "))
|
||
|
|
return
|
||
|
|
}
|
||
|
|
telegram.FlightNumber, telegram.RegisterNumber = parseFlight(values[1])
|
||
|
|
telegram.Departure = values[2]
|
||
|
|
telegram.Destination, telegram.DestinationTime = getAirportAndTime(values[3])
|
||
|
|
if l == 5 {
|
||
|
|
parseDof(telegram, values[4])
|
||
|
|
}
|
||
|
|
telegram.Parsed = true
|
||
|
|
}
|
||
|
|
|
||
|
|
func parseDof(telegram *Telegram, text string) {
|
||
|
|
if dof := getFields(DOFRegex, text); dof["dof"] == "DOF" {
|
||
|
|
telegram.DateOfFlight, _ = time.Parse("060102", dof["time"])
|
||
|
|
}
|
||
|
|
}
|