Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
PIM
KItinerary
Commits
750008b4
Commit
750008b4
authored
May 12, 2021
by
Volker Krause
Browse files
Port Renfe and Viarail extractors away from the deprecated Context API
parent
b92f8b7c
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/lib/scripts/renfe.js
View file @
750008b4
...
...
@@ -4,10 +4,10 @@
SPDX-License-Identifier: LGPL-2.0-or-later
*/
function
parsePdf
(
pdf
)
function
parsePdf
(
pdf
,
node
,
triggerNode
)
{
if
(
!
Context
.
barcode
)
return
null
;
if
(
!
triggerNode
.
content
)
return
;
// barcode content:
// 13x ticket number
...
...
@@ -22,22 +22,23 @@ function parsePdf(pdf)
// ".." (optional)
// 5x "CombinadoCercanias" (optional)
var
barcode
=
triggerNode
.
content
;
var
res
=
JsonLd
.
newTrainReservation
();
res
.
reservedTicket
.
ticketToken
=
"
dataMatrix:
"
+
Context
.
barcode
;
res
.
reservationFor
.
trainNumber
=
Context
.
barcode
.
substr
(
29
,
5
);
res
.
reservedTicket
.
ticketedSeat
.
seatSection
=
Context
.
barcode
.
substr
(
34
,
3
);
res
.
reservedTicket
.
ticketedSeat
.
seatNumber
=
Context
.
barcode
.
substr
(
37
,
3
);
res
.
reservationNumber
=
Context
.
barcode
.
substr
(
43
);
res
.
reservedTicket
.
ticketToken
=
"
dataMatrix:
"
+
barcode
;
res
.
reservationFor
.
trainNumber
=
barcode
.
substr
(
29
,
5
);
res
.
reservedTicket
.
ticketedSeat
.
seatSection
=
barcode
.
substr
(
34
,
3
);
res
.
reservedTicket
.
ticketedSeat
.
seatNumber
=
barcode
.
substr
(
37
,
3
);
res
.
reservationNumber
=
barcode
.
substr
(
43
);
var
text
=
pdf
.
pages
[
Context
.
pdfPageNumber
].
text
;
var
text
=
pdf
.
pages
[
triggerNode
.
location
].
text
;
var
dep
=
text
.
match
(
/Salida +
(
.*
?)
{2,}([\d\/]
+
)
+
(\d\d
:
\d\d)
/
);
res
.
reservationFor
.
departureStation
.
name
=
dep
[
1
];
res
.
reservationFor
.
departureStation
.
identifier
=
"
uic:71
"
+
Context
.
barcode
.
substr
(
13
,
5
);
res
.
reservationFor
.
departureStation
.
identifier
=
"
uic:71
"
+
barcode
.
substr
(
13
,
5
);
res
.
reservationFor
.
departureTime
=
JsonLd
.
toDateTime
(
dep
[
2
]
+
dep
[
3
],
"
dd/MM/yyyyhh:mm
"
,
"
es
"
);
var
arr
=
text
.
match
(
/Llegada
\s
+
(
.*
?)
{2,}([\d\/]
+
)
+
(\d\d
:
\d\d)\n
*
(\S
+
)
/
);
res
.
reservationFor
.
arrivalStation
.
name
=
arr
[
1
];
res
.
reservationFor
.
arrivalStation
.
identifier
=
"
uic:71
"
+
Context
.
barcode
.
substr
(
18
,
5
);
res
.
reservationFor
.
arrivalStation
.
identifier
=
"
uic:71
"
+
barcode
.
substr
(
18
,
5
);
res
.
reservationFor
.
arrivalTime
=
JsonLd
.
toDateTime
(
arr
[
2
]
+
arr
[
3
],
"
dd/MM/yyyyhh:mm
"
,
"
es
"
);
res
.
reservationFor
.
trainName
=
arr
[
4
];
...
...
src/lib/scripts/viarail.js
View file @
750008b4
...
...
@@ -4,9 +4,7 @@
SPDX-License-Identifier: LGPL-2.0-or-later
*/
function
parseBoardingPass
(
pdf
)
{
console
.
log
(
Context
.
barcode
);
function
parseBoardingPass
(
pdf
,
node
,
triggerNode
)
{
// barcode content
// 13x FTR number
// 29x traveler family name
...
...
@@ -24,17 +22,18 @@ function parseBoardingPass(pdf) {
// 12x purchase date/time as yyyyMMddhhmm
// 6x stuff, presumably class being part of this
var
barcode
=
triggerNode
.
content
;
var
res
=
JsonLd
.
newTrainReservation
();
res
.
reservationFor
.
provider
=
Context
.
barcode
.
substr
(
58
,
3
);
res
.
reservationFor
.
trainNumber
=
Context
.
barcode
.
substr
(
61
,
4
).
trim
();
res
.
reservationFor
.
departureTime
=
JsonLd
.
toDateTime
(
Context
.
barcode
.
substr
(
65
,
12
),
"
yyyyMMddhhmm
"
,
"
en
"
);
res
.
reservationFor
.
departureStation
.
name
=
Context
.
barcode
.
substr
(
50
,
4
);
res
.
reservationFor
.
arrivalStation
.
name
=
Context
.
barcode
.
substr
(
54
,
4
);
res
.
reservedTicket
.
ticketedSeat
.
seatSection
=
Context
.
barcode
.
substr
(
42
,
2
).
trim
();
res
.
reservedTicket
.
ticketedSeat
.
seatNumber
=
Context
.
barcode
.
substr
(
44
,
6
).
trim
();
res
.
reservedTicket
.
ticketToken
=
"
azteccode:
"
+
Context
.
barcode
;
res
.
underName
.
familyName
=
Context
.
barcode
.
substr
(
13
,
29
).
trim
();
res
.
underName
.
givenName
=
Context
.
barcode
.
substr
(
77
,
22
).
trim
();
res
.
reservationNumber
=
Context
.
barcode
.
substr
(
104
,
6
);
res
.
reservationFor
.
provider
=
barcode
.
substr
(
58
,
3
);
res
.
reservationFor
.
trainNumber
=
barcode
.
substr
(
61
,
4
).
trim
();
res
.
reservationFor
.
departureTime
=
JsonLd
.
toDateTime
(
barcode
.
substr
(
65
,
12
),
"
yyyyMMddhhmm
"
,
"
en
"
);
res
.
reservationFor
.
departureStation
.
name
=
barcode
.
substr
(
50
,
4
);
res
.
reservationFor
.
arrivalStation
.
name
=
barcode
.
substr
(
54
,
4
);
res
.
reservedTicket
.
ticketedSeat
.
seatSection
=
barcode
.
substr
(
42
,
2
).
trim
();
res
.
reservedTicket
.
ticketedSeat
.
seatNumber
=
barcode
.
substr
(
44
,
6
).
trim
();
res
.
reservedTicket
.
ticketToken
=
"
azteccode:
"
+
barcode
;
res
.
underName
.
familyName
=
barcode
.
substr
(
13
,
29
).
trim
();
res
.
underName
.
givenName
=
barcode
.
substr
(
77
,
22
).
trim
();
res
.
reservationNumber
=
barcode
.
substr
(
104
,
6
);
return
res
;
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment