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
9bb618ac
Commit
9bb618ac
authored
Oct 28, 2020
by
Volker Krause
Browse files
Extract tickets with SNCF's Secutix barcode variant
parent
2697985b
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/extractors/sncf.js
View file @
9bb618ac
...
...
@@ -113,6 +113,34 @@ function parsePdf(pdf) {
return
reservations
;
}
function
parseSecutixPdf
(
pdf
)
{
// see https://community.kde.org/KDE_PIM/KItinerary/SNCF_Barcodes#SNCF_Secutix_Tickets
var
res
=
JsonLd
.
newTrainReservation
();
var
code
=
Barcode
.
byteArrayToString
(
Context
.
barcode
);
res
.
reservationNumber
=
code
.
substr
(
268
,
9
);
res
.
reservationFor
.
departureStation
.
name
=
code
.
substr
(
277
,
5
);
res
.
reservationFor
.
departureStation
.
identifier
=
"
sncf:
"
+
code
.
substr
(
277
,
5
);
res
.
reservationFor
.
arrivalStation
.
name
=
code
.
substr
(
282
,
5
);
res
.
reservationFor
.
arrivalStation
.
identifier
=
"
sncf:
"
+
code
.
substr
(
282
,
5
);
res
.
reservationFor
.
departureDay
=
JsonLd
.
toDateTime
(
code
.
substr
(
343
,
8
),
"
ddMMyyyy
"
,
"
fr
"
);
res
.
reservedTicket
.
ticketedSeat
.
seatingType
=
code
.
substr
(
351
,
1
);
res
.
reservedTicket
.
ticketToken
=
"
aztecbin:
"
+
Barcode
.
toBase64
(
Context
.
barcode
);
res
.
underName
.
familyName
=
code
.
substr
(
376
,
19
);
res
.
underName
.
givenName
=
code
.
substr
(
395
,
19
);
var
text
=
pdf
.
pages
[
Context
.
pdfPageNumber
].
text
;
var
dep
=
text
.
match
(
/Départ
[^
]
+
(\d
+
\.\d
+
\.\d
+
)
à
(\d
+:
\d
+
)
[^
]
+
(
.*
)\n
/
);
var
arr
=
text
.
match
(
/Arrivée
[^
]
+
(\d
+
\.\d
+
\.\d
+
)
à
(\d
+:
\d
+
)
[^
]
+
(
.*
)\n\s
+
(
.*
)\n
/
);
res
.
reservationFor
.
departureStation
.
name
=
dep
[
3
];
res
.
reservationFor
.
departureTime
=
JsonLd
.
toDateTime
(
dep
[
1
]
+
dep
[
2
],
"
dd.MM.yyyyhh:mm
"
,
"
fr
"
);
res
.
reservationFor
.
arrivalStation
.
name
=
arr
[
3
];
res
.
reservationFor
.
arrivalTime
=
JsonLd
.
toDateTime
(
arr
[
1
]
+
arr
[
2
],
"
dd.MM.yyyyhh:mm
"
,
"
fr
"
);
res
.
reservationFor
.
trainNumber
=
arr
[
4
];
return
res
;
}
function
parseOuigoConfirmation
(
html
)
{
var
reservations
=
new
Array
();
...
...
src/extractors/sncf.json
View file @
9bb618ac
...
...
@@ -27,6 +27,17 @@
"script"
:
"sncf.js"
,
"type"
:
"Text"
},
{
"filter"
:
[
{
"match"
:
"^2200"
,
"type"
:
"Barcode"
}
],
"function"
:
"parseSecutixPdf"
,
"script"
:
"sncf.js"
,
"type"
:
"Pdf"
},
{
"filter"
:
[
{
...
...
src/jsapi/barcode.cpp
View file @
9bb618ac
...
...
@@ -133,4 +133,10 @@ void JsApi::Barcode::setContextDate(const QDateTime &dt)
m_contextDate
=
dt
;
}
QString
JsApi
::
Barcode
::
byteArrayToString
(
const
QVariant
&
b
)
const
{
const
auto
ba
=
b
.
toByteArray
();
return
QString
::
fromLatin1
(
ba
.
constData
(),
ba
.
size
());
}
#include "moc_barcode.cpp"
src/jsapi/barcode.h
View file @
9bb618ac
...
...
@@ -64,6 +64,10 @@ public:
Q_INVOKABLE
QVariant
fromBase64
(
const
QString
&
s
)
const
;
/** Converts the given QByteArray into a BitArray. */
Q_INVOKABLE
QVariant
toBitArray
(
const
QVariant
&
b
)
const
;
/** Converts the given QByteArray into a string for processing in JS.
* This only works if there isn't "too much" binary content in the byte array.
*/
Q_INVOKABLE
QString
byteArrayToString
(
const
QVariant
&
b
)
const
;
///@cond internal
void
setContextDate
(
const
QDateTime
&
dt
);
...
...
Write
Preview
Markdown
is supported
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