XMKLB6DI3SLWQ6DKAAL47VNZQGER5NRJKCPLMVZO4PYHGM3NQJAQC
let postal_code = [];
for(let i = 0; i < ab.length; ++i) {
ab[i] = ab[i].split('\t');
idx.push(i);
names.push(ab[i][1] = sanitize_name(ab[i][1]));
address.push(ab[i][2]);
postal_code.push(ab[i][3]);
city.push(ab[i][0]);
}
await postgres.query(
`create temporary table alberta as
select *
from unnest (
$1::smallint[],
$2::citext[],
$3::citext[],
$4::citext[],
$5::citext[]
) as t(idx, joined_name, address, city, postal_code)`,
[idx, names, address, city, postal_code]
);
idx = (await postgres.query(`
select idx
from alberta
where not exists (
select
from store_temp
where
joined_name = alberta.joined_name and
address = alberta.address and
address2 = '' and
city = alberta.city and
region = 'alberta' and
country = 'canada' and
postal_code = alberta.postal_code
)
`)).rows.map(x => x.idx);
names = [];
address = [];
let address2 = [];
city = [];
for(let i = 0; i < idk.length; ++i) {
for(let j = 0; j < results[i].length; ++j) {
idx.push(i);
jdx.push(j);
names.push(results[i][j][0] = sanitize_name(results[i][j][0]));
address.push(results[i][j][1]);
city.push(idk[i]);
}
}
await postgres.query(
`create temporary table manitoba as
select *
from unnest (
$1::smallint[],
$2::smallint[],
$3::citext[],
$4::citext[],
$5::citext[]
) as t(idx, jdx, joined_name, address, city)`,
[idx, jdx, names, address, city]
);
let temp = (await postgres.query(`
select idx, jdx
from manitoba
where not exists (
select
from store_temp
where
joined_name = manitoba.joined_name and
address = manitoba.address and
address2 = '' and
city = manitoba.city and
region = 'manitoba' and
country = 'canada' and
postal_code = ''
)
`)).rows;
idx = temp.map(x => x.idx);
jdx = temp.map(x => x.jdx);
names = [];
address = [];
let address2 = [];
city = [];
for(let i = 0; i < idk.length; ++i) {
for(let j = 0; j < results[i].length; ++j) {
let lol = sanitize_name(results[i][j][0]);
if(results[i][j][1] === 'Otineka Mall' && lol === 'Meta') {
names.push(lol);
address.push('Otineka Mall Highway 10 North');//gmaps ok
address2.push('Unit 128');
city.push('Opaskwayak');
region.push('Manitoba');
country.push('Canada');
postal_code.push('R0B2J0');
longitude.push('-101.261585');
latitude.push('53.834096');
osrm_hint_foot.push(await request(`http://127.0.0.1:5000/nearest/v1/fuck/-101.261585,53.834096`).then(x => JSON.parse(x).waypoints[0].hint));
osrm_hint_car.push(await request(`http://127.0.0.1:5001/nearest/v1/fuck/-101.261585,53.834096`).then(x => JSON.parse(x).waypoints[0].hint));
timezone.push('America/Winnipeg');
} else {
let r;
try {
r = await g(`${results[i][j][1]} ${idk[i]} manitoba canada`);
} catch(e) {
console.error(e);
console.log(results[i][j][0]);
for(let k = 0; k < idx.length; ++k) {
const i = idx[k];
const j = jdx[k];
if(results[i][j][1] === 'Otineka Mall' && results[i][j][0] === 'Meta') {
names.push(results[i][j][0]);
address.push('Otineka Mall Highway 10 North');//gmaps ok
address2.push('Unit 128');
city.push('Opaskwayak');
region.push('Manitoba');
country.push('Canada');
postal_code.push('R0B2J0');
longitude.push('-101.261585');
latitude.push('53.834096');
osrm_hint_foot.push(await request(`http://127.0.0.1:5000/nearest/v1/fuck/-101.261585,53.834096`).then(x => JSON.parse(x).waypoints[0].hint));
osrm_hint_car.push(await request(`http://127.0.0.1:5001/nearest/v1/fuck/-101.261585,53.834096`).then(x => JSON.parse(x).waypoints[0].hint));
timezone.push('America/Winnipeg');
} else {
let r;
try {
r = await g(`${results[i][j][1]} ${idk[i]} manitoba canada`);
} catch(e) {
console.error(e);
console.log(results[i][j]);
continue;
}
if(!pc.test(r[0].postal_code)) {
if(results[i][j][1] === '300A North Railway Street') {
r[0].postal_code = 'R6M1S7';
} else {
console.error('postal_code goofup', r, results[i][j], idk[i]);
names.push(lol);
address.push(r[0].address);
address2.push(results[i][j][1] === '300A North Railway Street' ? 'A' : r[0].address2);
city.push(r[0].city);
region.push(r[0].region);
country.push(r[0].country);
postal_code.push(r[0].postal_code);
longitude.push(r[1].lng);
latitude.push(r[1].lat);
osrm_hint_foot.push(r[3]);
osrm_hint_car.push(r[4]);
timezone.push(r[2]);
names.push(results[i][j][0]);
address.push(r[0].address);
address2.push(results[i][j][1] === '300A North Railway Street' ? 'A' : r[0].address2);
city.push(r[0].city);
region.push(r[0].region);
country.push(r[0].country);
postal_code.push(r[0].postal_code);
longitude.push(r[1].lng);
latitude.push(r[1].lat);
osrm_hint_foot.push(r[3]);
osrm_hint_car.push(r[4]);
timezone.push(r[2]);
for(let i = 0; i < results.length; ++i) {
idx.push(i);
names.push(results[i][0] = sanitize_name(results[i][0]));
address.push(results[i][1]);
city.push(results[i][2]);
}
await postgres.query(
`create temporary table saskatchewan as
select *
from unnest (
$1::smallint[],
$2::citext[],
$3::citext[],
$4::citext[]
) as t(idx, joined_name, address, city)`,
[idx, names, address, city]
);
idx = (await postgres.query(`
select idx
from saskatchewan
where not exists (
select
from store_temp
where
joined_name = saskatchewan.joined_name and
address = saskatchewan.address and
address2 = '' and
city = saskatchewan.city and
region = 'saskatchewan' and
country = 'canada' and
postal_code = ''
)
`)).rows.map(x => x.idx);
names = [];
address = [];
let address2 = [];
city = [];
for(let i = 0; i < results.length; ++i) {
idx.push(i);
address.push(results[i][1]);
}
await postgres.query(
`create temporary table newbrunswick as
select *
from unnest (
$1::smallint[],
$2::citext[]
) as t(idx, address)`,
[idx, address]
);
idx = (await postgres.query(`
select idx
from newbrunswick
where not exists (
select
from store_temp
where
joined_name = '' and
address = newbrunswick.address and
address2 = '' and
city = '' and
region = 'newbrunswick' and
country = 'canada' and
postal_code = ''
)
`)).rows.map(x => x.idx);
address = [];
let city = [];
let postal_code = [];
for(let i = 0; i < bc.length; ++i) {
if(bc[i].Status === 'Open') {
idx.push(i);
names.push(bc[i].Name = sanitize_name(bc[i].Name));
address.push(bc[i].Address);
city.push(bc[i].City);
postal_code.push(bc[i].Postal);
}
}
await postgres.query(
`create temporary table britishcolumbia as
select *
from unnest (
$1::smallint[],
$2::citext[],
$3::citext[],
$4::citext[],
$5::citext[]
) as t(idx, joined_name, address, city, postal_code)`,
[idx, names, address, city, postal_code]
);
idx = (await postgres.query(`
select idx
from britishcolumbia
where not exists (
select
from store_temp
where
joined_name = britishcolumbia.joined_name and
address = britishcolumbia.address and
address2 = '' and
city = britishcolumbia.city and
region = 'britishcolumbia' and
country = 'canada' and
postal_code = britishcolumbia.postal_code
)
`)).rows.map(x => x.idx);
names = [];
address = [];
for(let i = 0; i < bc.length; ++i) {
if(bc[i].Status === 'Open') {
let r;
try {
r = await g(`${bc[i].Address} ${bc[i].City} british columbia ${bc[i].Postal} canada`);
} catch(e) {
console.error(e);
console.log(bc[i].Name);
for(let j = 0; j < idx.length; ++j) {
const i = idx[j];
let r;
try {
r = await g(`${bc[i].Address} ${bc[i].City} british columbia ${bc[i].Postal} canada`);
} catch(e) {
console.error(e);
console.log(bc[i]);
continue;
}
if(!pc.test(r[0].postal_code)) {
bc[i].Postal = bc[i].Postal.replace(/\s+/g, '');
if(r[0].postal_code.length === 3 && bc[i].Postal.length === 6) {
r[0].postal_code = bc[i].Postal
} else {
console.error('postal_code goofup', r, bc[i]);
if(!pc.test(r[0].postal_code)) {
bc[i].Postal = bc[i].Postal.replace(/\s+/g, '');
if(r[0].postal_code.length === 3 && bc[i].Postal.length === 6) {
r[0].postal_code = bc[i].Postal
} else {
console.error('postal_code goofup', r, bc[i]);
continue;
}
}
names.push(sanitize_name(bc[i].Name));
address.push(r[0].address);
address2.push(r[0].address2);
city.push(r[0].city);
region.push(r[0].region);
country.push(r[0].country);
postal_code.push(r[0].postal_code);
longitude.push(r[1].lng);
latitude.push(r[1].lat);
osrm_hint_foot.push(r[3]);
osrm_hint_car.push(r[4]);
timezone.push(r[2]);
phone.push(bc[i].Phone);
names.push(bc[i].Name);
address.push(r[0].address);
address2.push(r[0].address2);
city.push(r[0].city);
region.push(r[0].region);
country.push(r[0].country);
postal_code.push(r[0].postal_code);
longitude.push(r[1].lng);
latitude.push(r[1].lat);
osrm_hint_foot.push(r[3]);
osrm_hint_car.push(r[4]);
timezone.push(r[2]);
phone.push(bc[i].Phone);
let postal_code = [];
for(let i = 0; i < nl.length; ++i) {
idx.push(i);
names.push(nl[i].name = sanitize_name(nl[i].name));
address.push(nl[i].address);
address2.push(nl[i].address2);
city.push(nl[i].city);
postal_code.push(nl[i].postal_zip);
}
await postgres.query(
`create temporary table newfoundland as
select *
from unnest (
$1::smallint[],
$2::citext[],
$3::citext[],
$4::citext[],
$5::citext[],
$6::citext[]
) as t(idx, joined_name, address, address2, city, postal_code)`,
[idx, names, address, address2, city, postal_code]
);
idx = (await postgres.query(`
select idx
from newfoundland
where not exists (
select
from store_temp
where
joined_name = newfoundland.joined_name and
address = newfoundland.address and
address2 = newfoundland.address2 and
city = newfoundland.city and
region = 'newfoundland' and
country = 'canada' and
postal_code = newfoundland.postal_code
)
`)).rows.map(x => x.idx);
names = [];
address = [];
address2 = [];
city = [];
let postal_code = [];
for(let i = 0; i < x.length; ++i) {
for(let j = 0; j < x[i].features.length; ++j) {
if(x[i].features[j].featureId === 'CP') {
idx.push(i);
address.push(x[i].addressInfo.address1);
address2.push(x[i].addressInfo.address2 ?? '');
city.push(x[i].addressInfo.city);
postal_code.push(x[i].addressInfo.postal);
break;
}
}
}
await postgres.query(
`create temporary table novascotia as
select *
from unnest (
$1::smallint[],
$2::citext[],
$3::citext[],
$4::citext[],
$5::citext[]
) as t(idx, address, address2, city, postal_code)`,
[idx, address, address2, city, postal_code]
);
idx = (await postgres.query(`
select idx
from novascotia
where not exists (
select
from store_temp
where
joined_name = '' and
address = novascotia.address and
address2 = novascotia.address2 and
city = novascotia.city and
region = 'novascotia' and
country = 'canada' and
postal_code = novascotia.postal_code
)
`)).rows.map(x => x.idx);
address = [];
address2 = [];
city = [];
for(let i = 0; i < x.length; ++i) {
for(let j = 0; j < x[i].features.length; ++j) {
if(x[i].features[j].featureId === 'CP') {
let r;
try {
r = await g(`${x[i].addressInfo.address1} ${x[i].addressInfo.address2 ?? ''} ${x[i].addressInfo.city} nova scotia ${x[i].addressInfo.postal} canada`);
} catch(e) {
console.error(e);
console.log(x[i].name);
continue;
for(let j = 0; j < idx.length; ++j) {
const i = idx[j];
let r;
try {
r = await g(`${x[i].addressInfo.address1} ${x[i].addressInfo.address2 ?? ''} ${x[i].addressInfo.city} nova scotia ${x[i].addressInfo.postal} canada`);
} catch(e) {
console.error(e);
console.log(x[i].name);
continue;
}
if(!pc.test(r[0].postal_code)) {
x[i].postal = x[i].postal.replace(/\s+/g, '');
if(r[0].postal_code.length === 3 && x[i].postal.length === 6) {
r[0].postal_code = x[i].postal
} else {
console.error('postal_code goofup', r, x[i]);
continue;
}
}
address.push(r[0].address);
address2.push(r[0].address2);
city.push(r[0].city);
region.push(r[0].region);
country.push(r[0].country);
postal_code.push(r[0].postal_code);
longitude.push(r[1].lng);
latitude.push(r[1].lat);
osrm_hint_foot.push(r[3]);
osrm_hint_car.push(r[4]);
timezone.push(r[2]);
phone.push(x[i].phone);
let tim = [];
for(let k = 0; k < x[i].openingHours.length; ++k) {
let d = 0;
switch(x[i].openingHours[k].dayOfWeek) {
case 'Tuesday': d = 1440; break;
case 'Wednesday': d = 2880; break;
case 'Thursday': d = 4320; break;
case 'Friday': d = 5760; break;
case 'Saturday': d = 7200; break;
case 'Sunday': d = 8640; break;
}
let beg = x[i].openingHours[k].opens.split(':').map(Number);
beg = beg[0] * 60 + beg[1];
let end = x[i].openingHours[k].closes.split(':').map(Number);
end = end[0] * 60 + end[1];
let rtn = [d + beg, d + end];
if(end < beg) {
if(d === 8640) {
tim.push([rtn[0], 10080]);
rtn[0] = 0;
rtn[1] -= 8640;
} else {
rtn[1] += 1440;
if(!pc.test(r[0].postal_code)) {
x[i].postal = x[i].postal.replace(/\s+/g, '');
if(r[0].postal_code.length === 3 && x[i].postal.length === 6) {
r[0].postal_code = x[i].postal
} else {
console.error('postal_code goofup', r, x[i]);
continue;
}
}
address.push(r[0].address);
address2.push(r[0].address2);
city.push(r[0].city);
region.push(r[0].region);
country.push(r[0].country);
postal_code.push(r[0].postal_code);
longitude.push(r[1].lng);
latitude.push(r[1].lat);
osrm_hint_foot.push(r[3]);
osrm_hint_car.push(r[4]);
timezone.push(r[2]);
phone.push(x[i].phone);
let tim = [];
for(let k = 0; k < x[i].openingHours.length; ++k) {
let d = 0;
switch(x[i].openingHours[k].dayOfWeek) {
case 'Tuesday': d = 1440; break;
case 'Wednesday': d = 2880; break;
case 'Thursday': d = 4320; break;
case 'Friday': d = 5760; break;
case 'Saturday': d = 7200; break;
case 'Sunday': d = 8640; break;
}
let beg = x[i].openingHours[k].opens.split(':').map(Number);
beg = beg[0] * 60 + beg[1];
let end = x[i].openingHours[k].closes.split(':').map(Number);
end = end[0] * 60 + end[1];
let rtn = [d + beg, d + end];
if(end < beg) {
if(d === 8640) {
tim.push([rtn[0], 10080]);
rtn[0] = 0;
rtn[1] -= 8640;
} else {
rtn[1] += 1440;
}
}
tim.push(rtn);
}
open.push(JSON.stringify(tim));
break;
results[i] = {adr, tim, phone};
idx.push(i);
address.push(adr);
}
await postgres.query(
`create temporary table pei as
select *
from unnest (
$1::smallint[],
$2::citext[]
) as t(idx, address)`,
[idx, address]
);
idx = (await postgres.query(`
select idx
from pei
where not exists (
select
from store_temp
where
joined_name = '' and
address = pei.address and
address2 = '' and
city = '' and
region = 'pei' and
country = 'canada' and
postal_code = ''
)
`)).rows.map(x => x.idx);
address = [];
let address2 = [];
let city = [];
let region = [];
let country = [];
let postal_code = [];
let longitude = [];
let latitude = [];
let osrm_hint_foot = [];
let osrm_hint_car = [];
let timezone = [];
let open = [];
let phone = [];
for(let j = 0; j < idx.length; ++j) {
const i = idx[j];
let address = [];
let results = await page.$$eval('.component-store-location__address', x => x.map(y => Array.from(y.querySelectorAll('p')).map(z => z.textContent.trim())));
page.close();
for(let i = 0; i < results.length; ++i) {
idx.push(i);
address.push(results[i][0]);
}
await postgres.query(
`create temporary table yukon as
select *
from unnest (
$1::smallint[],
$2::citext[],
$3::citext[]
) as t(idx, joined_name, address)`,
[idx, n, address]
);
idx = (await postgres.query(`
select idx
from yukon
where not exists (
select
from store_temp
where
joined_name = yukon.joined_name and
address = yukon.address and
address2 = '' and
city = '' and
region = 'yukon' and
country = 'canada' and
postal_code = ''
)
`)).rows.map(x => x.idx);
let results = await page.$$eval('.component-store-location__address', x => x.map(y => Array.from(y.querySelectorAll('p')).map(z => z.textContent.trim())));
page.close();
for(let i = 0; i < results.length; ++i) {
for(let j = 0; j < idx.length; ++j) {
const i = idx[j];
for(let j = 0; j < results[i].length; ++j) {
if(results[i][j].startsWith('http')) {
u = results[i][j];
} else if(results[i][j].replace(/\D/g, '').length >= 10) {
p = results[i][j];
for(let k = 1; k < results[i].length; ++k) {
if(results[i][k].startsWith('http')) {
u = results[i][k];
} else if(results[i][k].replace(/\D/g, '').length === 10) {
p = results[i][k];
idx.push(i);
names.push(results[i][0] = sanitize_name(results[i][0]));
address.push(results[i][1]);
}
await postgres.query(
`create temporary table nwt as
select *
from unnest (
$1::smallint[],
$2::citext[],
$3::citext[]
) as t(idx, joined_name, address)`,
[idx, names, address]
);
idx = (await postgres.query(`
select idx
from nwt
where not exists (
select
from store_temp
where
joined_name = nwt.joined_name and
address = nwt.address and
address2 = '' and
city = '' and
region = 'nwt' and
country = 'canada' and
postal_code = ''
)
`)).rows.map(x => x.idx);
names = [];
address = [];
let address2 = [];
let city = [];
let region = [];
let country = [];
let postal_code = [];
let longitude = [];
let latitude = [];
let osrm_hint_foot = [];
let osrm_hint_car = [];
let timezone = [];
let phone = [];
for(let j = 0; j < idx.length; ++j) {
const i = idx[j];
let r;
try {
r = await g(on[i][11]);
} catch(e) {
console.error(e);
console.log(on[i][6]);
continue;
}
if(!pc.test(r[0].postal_code)) {
on[i][10] = on[i][10].replace(/\s+/g, '');
if(r[0].postal_code.length === 3 && on[i][10].length === 6) {
r[0].postal_code = on[i][10]
} else {
console.error('postal_code goofup', r, on[i]);
continue;
}
}
names.push(sanitize_name(on[i][6])
idx.push(i);
names.push(on[i][6] = sanitize_name(on[i][6])
address.push(r[0].address);
address2.push(r[0].address2);
city.push(r[0].city);
region.push(r[0].region);
country.push(r[0].country);
postal_code.push(r[0].postal_code);
longitude.push(r[1].lng);
latitude.push(r[1].lat);
osrm_hint_foot.push(r[3]);
osrm_hint_car.push(r[4]);
timezone.push(r[2]);
address.push(on[i][11]);
}
}
await postgres.query(
`create temporary table ontario as
select *
from unnest (
$1::smallint[],
$2::citext[],
$3::citext[]
) as t(idx, joined_name, address)`,
[idx, names, address]
);
idx = (await postgres.query(`
select idx
from ontario
where not exists (
select
from store_temp
where
joined_name = ontario.joined_name and
address = ontario.address and
address2 = '' and
city = '' and
region = 'ontario' and
country = 'canada' and
postal_code = ''
)
`)).rows.map(x => x.idx);
names = [];
address = [];
let address2 = [];
let city = [];
let region = [];
let country = [];
let postal_code = [];
let longitude = [];
let latitude = [];
let osrm_hint_foot = [];
let osrm_hint_car = [];
let timezone = [];
for(let j = 0; j < idx.length; ++j) {
const i = idx[j];
let r;
try {
r = await g(on[i][11].replace(/OSPREY MIIKAN RD/i, 'OSPREY MIIKAN'));
} catch(e) {
console.error(e);
console.log(on[i]);
continue;
}
if(!pc.test(r[0].postal_code)) {
on[i][10] = on[i][10].replace(/\s+/g, '');
if(r[0].postal_code.length === 3 && on[i][10].length === 6) {
r[0].postal_code = on[i][10];
} else {
console.error('postal_code goofup', r, on[i]);
continue;
}
names.push(on[i][6]);
address.push(r[0].address);
address2.push(r[0].address2);
city.push(r[0].city);
region.push(r[0].region);
country.push(r[0].country);
postal_code.push(r[0].postal_code);
longitude.push(r[1].lng);
latitude.push(r[1].lat);
osrm_hint_foot.push(r[3]);
osrm_hint_car.push(r[4]);
timezone.push(r[2]);
let postal_code = [];
for(let i = 0; i < results.length; ++i) {
idx.push(i);
address.push(results[i].Address.Line1);
address2.push(results[i].Address.Line2 ?? '');
city.push(results[i].Address.City);
postal_code.push(results[i].Address.PostalCode);
}
await postgres.query(
`create temporary table quebec as
select *
from unnest (
$1::smallint[],
$2::citext[],
$3::citext[],
$4::citext[],
$5::citext[]
) as t(idx, address, address2, city, postal_code)`,
[idx, address, address2, city, postal_code]
);
idx = (await postgres.query(`
select idx
from quebec
where not exists (
select
from store_temp
where
joined_name = '' and
address = quebec.address and
address2 = quebec.address2 and
city = quebec.city and
region = 'quebec' and
country = 'canada' and
postal_code = quebec.postal_code
)
`)).rows.map(x => x.idx);
address = [];
address2 = [];
city = [];
await postgres.query(`
create temporary table store_temp_temp as
select
joined_name,
address,
'' as address2,
city,
'alberta' as region,
'canada' as country,
postal_code
from alberta
union all
select
joined_name,
address,
'',
city,
'manitoba',
'canada',
''
from manitoba
union all
select
joined_name,
address,
'',
city,
'saskatchewan',
'canada',
''
from saskatchewan
union all
select
'',
address,
'',
'',
'newbrunswick',
'canada',
''
from newbrunswick
union all
select
joined_name,
address,
'',
city,
'britishcolumbia',
'canada',
postal_code
from britishcolumbia
union all
select
joined_name,
address,
address2,
city,
'newfoundland',
'canada',
postal_code
from newfoundland
union all
select
'',
address,
address2,
city,
'novascotia',
'canada',
postal_code
from novascotia
union all
select
'',
address,
'',
'',
'pei',
'canada',
''
from pei
union all
select
joined_name,
address,
'',
'',
'yukon',
'canada',
''
from yukon
union all
select
joined_name,
address,
'',
'',
'nwt',
'canada',
''
from nwt
union all
select
joined_name,
address,
'',
'',
'ontario',
'canada',
''
from ontario
union all
select
'',
address,
address2,
city,
'quebec',
'canada',
postal_code
from quebec
`);
let removeQ = (await postgres.query(`
select *
from store_temp
where not exists (
select
from store_temp_temp
where
joined_name = store_temp.joined_name and
address = store_temp.address and
address2 = store_temp.address2 and
city = store_temp.city and
region = store_temp.region and
country = store_temp.country and
postal_code = store_temp.postal_code
)
`)).rows;
if(removeQ.length) {
console.log('human, should these be removed?', removeQ);
}
await postgres.query('truncate store_temp');
await postgres.query('insert into store_temp select * from store_temp_temp');