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 asselect *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 idxfrom albertawhere not exists (selectfrom store_tempwherejoined_name = alberta.joined_name andaddress = alberta.address andaddress2 = '' andcity = alberta.city andregion = 'alberta' andcountry = 'canada' andpostal_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 asselect *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, jdxfrom manitobawhere not exists (selectfrom store_tempwherejoined_name = manitoba.joined_name andaddress = manitoba.address andaddress2 = '' andcity = manitoba.city andregion = 'manitoba' andcountry = 'canada' andpostal_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 okaddress2.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 okaddress2.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 asselect *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 idxfrom saskatchewanwhere not exists (selectfrom store_tempwherejoined_name = saskatchewan.joined_name andaddress = saskatchewan.address andaddress2 = '' andcity = saskatchewan.city andregion = 'saskatchewan' andcountry = 'canada' andpostal_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 asselect *from unnest ($1::smallint[],$2::citext[]) as t(idx, address)`,[idx, address]);idx = (await postgres.query(`select idxfrom newbrunswickwhere not exists (selectfrom store_tempwherejoined_name = '' andaddress = newbrunswick.address andaddress2 = '' andcity = '' andregion = 'newbrunswick' andcountry = 'canada' andpostal_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 asselect *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 idxfrom britishcolumbiawhere not exists (selectfrom store_tempwherejoined_name = britishcolumbia.joined_name andaddress = britishcolumbia.address andaddress2 = '' andcity = britishcolumbia.city andregion = 'britishcolumbia' andcountry = 'canada' andpostal_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 asselect *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 idxfrom newfoundlandwhere not exists (selectfrom store_tempwherejoined_name = newfoundland.joined_name andaddress = newfoundland.address andaddress2 = newfoundland.address2 andcity = newfoundland.city andregion = 'newfoundland' andcountry = 'canada' andpostal_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 asselect *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 idxfrom novascotiawhere not exists (selectfrom store_tempwherejoined_name = '' andaddress = novascotia.address andaddress2 = novascotia.address2 andcity = novascotia.city andregion = 'novascotia' andcountry = 'canada' andpostal_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 asselect *from unnest ($1::smallint[],$2::citext[]) as t(idx, address)`,[idx, address]);idx = (await postgres.query(`select idxfrom peiwhere not exists (selectfrom store_tempwherejoined_name = '' andaddress = pei.address andaddress2 = '' andcity = '' andregion = 'pei' andcountry = 'canada' andpostal_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 asselect *from unnest ($1::smallint[],$2::citext[],$3::citext[]) as t(idx, joined_name, address)`,[idx, n, address]);idx = (await postgres.query(`select idxfrom yukonwhere not exists (selectfrom store_tempwherejoined_name = yukon.joined_name andaddress = yukon.address andaddress2 = '' andcity = '' andregion = 'yukon' andcountry = 'canada' andpostal_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 asselect *from unnest ($1::smallint[],$2::citext[],$3::citext[]) as t(idx, joined_name, address)`,[idx, names, address]);idx = (await postgres.query(`select idxfrom nwtwhere not exists (selectfrom store_tempwherejoined_name = nwt.joined_name andaddress = nwt.address andaddress2 = '' andcity = '' andregion = 'nwt' andcountry = 'canada' andpostal_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 asselect *from unnest ($1::smallint[],$2::citext[],$3::citext[]) as t(idx, joined_name, address)`,[idx, names, address]);idx = (await postgres.query(`select idxfrom ontariowhere not exists (selectfrom store_tempwherejoined_name = ontario.joined_name andaddress = ontario.address andaddress2 = '' andcity = '' andregion = 'ontario' andcountry = 'canada' andpostal_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 asselect *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 idxfrom quebecwhere not exists (selectfrom store_tempwherejoined_name = '' andaddress = quebec.address andaddress2 = quebec.address2 andcity = quebec.city andregion = 'quebec' andcountry = 'canada' andpostal_code = quebec.postal_code)`)).rows.map(x => x.idx);address = [];address2 = [];city = [];
await postgres.query(`create temporary table store_temp_temp asselectjoined_name,address,'' as address2,city,'alberta' as region,'canada' as country,postal_codefrom albertaunion allselectjoined_name,address,'',city,'manitoba','canada',''from manitobaunion allselectjoined_name,address,'',city,'saskatchewan','canada',''from saskatchewanunion allselect'',address,'','','newbrunswick','canada',''from newbrunswickunion allselectjoined_name,address,'',city,'britishcolumbia','canada',postal_codefrom britishcolumbiaunion allselectjoined_name,address,address2,city,'newfoundland','canada',postal_codefrom newfoundlandunion allselect'',address,address2,city,'novascotia','canada',postal_codefrom novascotiaunion allselect'',address,'','','pei','canada',''from peiunion allselectjoined_name,address,'','','yukon','canada',''from yukonunion allselectjoined_name,address,'','','nwt','canada',''from nwtunion allselectjoined_name,address,'','','ontario','canada',''from ontariounion allselect'',address,address2,city,'quebec','canada',postal_codefrom quebec`);let removeQ = (await postgres.query(`select *from store_tempwhere not exists (selectfrom store_temp_tempwherejoined_name = store_temp.joined_name andaddress = store_temp.address andaddress2 = store_temp.address2 andcity = store_temp.city andregion = store_temp.region andcountry = store_temp.country andpostal_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');