Verified Commit a06afded authored by Luca Beltrame's avatar Luca Beltrame
Browse files

Fix extraction of Japanese booking.com reservations

Summary:
Booking.com's emails have several quirks when done with Japanese hotels:

1. There is no indication of the country
2. The address contains the hotel name twice: once Romanized, once in
   Japanese
3. The address has two fields (one Romanized, one Japanese)
4. The order of the Japanese addresses is different

This is somewhat a hack, but the booking.com emails are not structured
enough to extract the information.

Test Plan:
Tested a Japanese reservation HTML from booking.com, worked. Tested a
non-Japanese reservation from booking.com, worked.

Reviewers: vkrause

Reviewed By: vkrause

Subscribers: kde-pim

Tags: #kde_pim

Differential Revision: https://phabricator.kde.org/D26258
parent 187c2d0d
......@@ -109,11 +109,31 @@ function parseHtml(doc)
res.reservationFor.name = elem.eval("(.//b|.//strong)")[0].content;
var fullAddr = elem.eval(".//tr")[1].recursiveContent;
var addr = fullAddr.match(/^(.*), (.*?), (.*?), ([^,]*?)\s*-?\s*$/);
res.reservationFor.address.streetAddress = addr[1];
res.reservationFor.address.addressLocality = addr[2];
res.reservationFor.address.postalCode = addr[3];
res.reservationFor.address.addressCountry = addr[4];
var addrRegex = /^(.*), (.*?), (.*?), ([^,]*?)\s*-?\s*$/;
//HACK: Japanese addresses do not have the country set in Booking.com HTML
// and have a different HTML structure
if (!addrRegex.test(fullAddr)) {
// The first two elements are the hotel name and the hotel name in
// Japanese, skip to the third
var addressElement = elem.eval("string(.//tr[3]//td)");
// Booking.com addresses are always separated by "\n-\n"
// We split and get the first part, which is the romanized address
var fullAddr = addressElement.split("\n-\n")[0]
// Replace double spaces from the extraction
fullAddr = fullAddr.replace(/\s+/g, ' ');
var addr = fullAddr.match(addrRegex);
res.reservationFor.address.streetAddress = addr[4];
res.reservationFor.address.addressLocality = addr[2];
res.reservationFor.address.postalCode = addr[1];
res.reservationFor.addressCountry = "Japan";
} else {
var addr = fullAddr.match(addrRegex);
res.reservationFor.address.streetAddress = addr[1];
res.reservationFor.address.addressLocality = addr[2];
res.reservationFor.address.postalCode = addr[3];
res.reservationFor.address.addressCountry = addr[4];
}
res.reservationFor.telephone = elem.eval(".//*[@class=\"u-phone\"]")[0].content;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment