95 lines
3.5 KiB
JavaScript
95 lines
3.5 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.writeReport = exports.WRITERS = exports.writerXLS = void 0;
|
|
const path = require("path");
|
|
const node_xlsx_1 = require("node-xlsx");
|
|
const write_1 = require("@plastichub/fs/write");
|
|
const __1 = require("..");
|
|
const fs_1 = require("@plastichub/osr-commons");
|
|
const extension = (file) => path.parse(file).ext;
|
|
const createGoogleMapLink = (latitude, longitude, zoomLevel) => {
|
|
const link = `https://www.google.com/maps/@${latitude},${longitude},${zoomLevel}z`;
|
|
return link;
|
|
};
|
|
const createGoogleMapLinkFromPlaceId = (placeId) => {
|
|
const link = `https://www.google.com/maps/place/?q=place_id:${placeId}`;
|
|
return link;
|
|
};
|
|
const writerXLS = (locations, dst, opts) => {
|
|
if (dst) {
|
|
let _path = path.resolve((0, fs_1.resolve)(dst, false, {
|
|
QUERY: opts.query,
|
|
FROM: opts.location,
|
|
ENGINE: opts.engine,
|
|
DOMAIN: opts.google_domain,
|
|
LANG: opts.language
|
|
}));
|
|
const locationsMap = locations.map((u) => {
|
|
return [
|
|
u.position,
|
|
u.title,
|
|
'',
|
|
u.phone,
|
|
u.type,
|
|
u.address,
|
|
u.website,
|
|
u.gps_coordinates.latitude + ',' + u.gps_coordinates.longitude,
|
|
0,
|
|
u.reviews,
|
|
u.rating,
|
|
createGoogleMapLinkFromPlaceId(u.place_id),
|
|
createGoogleMapLink(u.gps_coordinates.latitude, u.gps_coordinates.longitude, 9)
|
|
];
|
|
});
|
|
let columns = [
|
|
'Position',
|
|
'Title',
|
|
'EMail',
|
|
'Phone',
|
|
'Type',
|
|
'Address',
|
|
'Web',
|
|
'Coords',
|
|
'Status',
|
|
'Reviews',
|
|
'Rating',
|
|
'Map Place',
|
|
'Map Link'
|
|
];
|
|
let data = [
|
|
columns,
|
|
...locationsMap
|
|
];
|
|
const sheetOptions = { '!cols': [{ wch: 5 }, { wch: 30 }, { wch: 30 }, { wch: 30 }, , { wch: 30 }, { wch: 40 }] };
|
|
const buffer = node_xlsx_1.default.build([{ name: 'raw', data: data, options: sheetOptions }]);
|
|
(0, write_1.sync)(_path, buffer);
|
|
opts.debug && __1.logger.debug(`Writing users to ${_path} `);
|
|
}
|
|
};
|
|
exports.writerXLS = writerXLS;
|
|
const writerMarkdown = (locations, dst, opts) => {
|
|
if (dst) {
|
|
let _path = path.resolve((0, fs_1.resolve)(dst, false, {
|
|
QUERY: opts.query,
|
|
FROM: opts.location,
|
|
ENGINE: opts.engine,
|
|
DOMAIN: opts.google_domain,
|
|
LANG: opts.language
|
|
}));
|
|
const bulletList = locations.map((u) => `- ${u.title} (${u.address} ) - [${u.website}](${u.website}) -
|
|
[Phone: ${u.phone}] -
|
|
[Google Place](${createGoogleMapLinkFromPlaceId(u.place_id)}) -
|
|
[Maps](${createGoogleMapLink(u.gps_coordinates.latitude, u.gps_coordinates.longitude, 9)})
|
|
`);
|
|
const markdownContent = `### ${opts.query} \n\n ${bulletList.join('\n')}`;
|
|
(0, write_1.sync)(_path, markdownContent);
|
|
opts.debug && __1.logger.debug(`Writing users to ${_path} `);
|
|
}
|
|
};
|
|
exports.WRITERS = {
|
|
'.xls': exports.writerXLS,
|
|
'.md': writerMarkdown
|
|
};
|
|
const writeReport = (locations, dst, opts) => exports.WRITERS[extension(dst)](locations, dst, opts);
|
|
exports.writeReport = writeReport;
|
|
//# sourceMappingURL=report_map.js.map
|