Added Top Web Models profile scraper.

This commit is contained in:
DebaucheryLibrarian
2021-01-16 04:10:43 +01:00
parent b9e4764516
commit e3ef0a0d69
5 changed files with 98 additions and 0 deletions

View File

@@ -1,5 +1,9 @@
'use strict';
const { convert, convertMany } = require('convert');
const logger = require('../logger')(__filename);
function inchesToCm(inches) {
if (!inches) return null;
@@ -54,6 +58,31 @@ function kgToLbs(kgs) {
return Math.round(Number(kilos) / 0.453592);
}
function convertManyApi(input, to) {
const curatedInput = input
.replace('\'', 'ft')
.replace('"', 'in');
return Math.round(convertMany(curatedInput).to(to)) || null;
}
function convertApi(input, fromOrTo, to) {
if (!input) {
return null;
}
try {
if (typeof input === 'string' && to === undefined) {
return convertManyApi(input, fromOrTo);
}
return Math.round(convert(input).from(fromOrTo).to(to)) || null;
} catch (error) {
logger.error(error);
return null;
}
}
module.exports = {
cmToFeetInches,
cmToInches,
@@ -62,4 +91,5 @@ module.exports = {
inchesToCm,
lbsToKg,
kgToLbs,
convert: convertApi,
};