mono/packages/search/lib/report_map.js
2025-03-11 11:28:14 +01:00

115 lines
3.9 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.writeReport = exports.WRITERS = exports.writerXLS = exports.writerJSON = void 0;
const path = require("path");
const node_xlsx_1 = require("node-xlsx");
const write_1 = require("@plastichub/fs/write");
const __1 = require("..");
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 writerJSON = (locations, dst, opts) => {
if (!dst) {
return;
}
__1.logger.debug(`Writing users to ${dst}`);
(0, write_1.sync)(opts.dst, locations);
};
exports.writerJSON = writerJSON;
const writerXLS = (locations, dst, opts) => {
if (dst) {
const locationsMap = locations.map((u) => {
return [
u.position,
u.title,
'',
'',
u.email,
u.phone,
u.type,
u.address,
u.website,
u.instagram,
u.youtube,
u.facebook,
u.linkedin,
u.twitter,
u.gps_coordinates.latitude + ',' + u.gps_coordinates.longitude,
0,
u.reviews,
u.rating,
u.geo.continent,
u.geo.countryName,
u.geo.city,
createGoogleMapLinkFromPlaceId(u.place_id),
createGoogleMapLink(u.gps_coordinates.latitude, u.gps_coordinates.longitude, 9)
];
});
let columns = [
'Position',
'Title',
'EMail',
'EMail - Finder.io',
'EMail - ChatGPT',
'Phone',
'Type',
'Address',
'Web',
'Instagram',
'Youtube',
'Facebook',
'Linkedin',
'Twitter',
'Coords',
'Status',
'Reviews',
'Rating',
'Continent',
'Country',
'City',
'Map Place',
'Map Link'
];
let data = [
columns,
...locationsMap
];
const sheetOptions = { '!cols': [{ wch: 5 }, { wch: 10 }, { wch: 10 }, { wch: 30 }, , { wch: 30 }, { wch: 40 }] };
const buffer = node_xlsx_1.default.build([{ name: 'raw', data: data, options: sheetOptions }]);
(0, write_1.sync)(opts.dst, buffer);
opts.debug && __1.logger.debug(`Writing users to ${opts.dst}`);
return data;
}
};
exports.writerXLS = writerXLS;
const writerMarkdown = (locations, dst, opts) => {
if (dst) {
const bulletList = locations.map((u) => `- ${u.title} (${u.address} ) - [${u.website}](${u.website}) -
[Phone: ${u.phone}] -
[Google Place](${createGoogleMapLinkFromPlaceId(u.place_id)}) -
[Continent] ${u.geo.continent} -
[Country] ${u.geo.countryName} -
[City] ${u.geo.city} -
[Maps](${createGoogleMapLink(u.gps_coordinates.latitude, u.gps_coordinates.longitude, 9)})
`);
const markdownContent = `### ${opts.query} \n\n ${bulletList.join('\n')}`;
(0, write_1.sync)(opts.dst, markdownContent);
opts.debug && __1.logger.debug(`Writing users to ${opts.dst}`);
return markdownContent;
}
};
exports.WRITERS = {
'.xls': exports.writerXLS,
'.json': exports.writerJSON,
'.xlsx': exports.writerXLS,
'.md': writerMarkdown
};
const writeReport = (locations, dst, opts) => exports.WRITERS[extension(dst)](locations, dst, opts);
exports.writeReport = writeReport;
//# sourceMappingURL=report_map.js.map