first commit
This commit is contained in:
67
config/index.js
Normal file
67
config/index.js
Normal file
@@ -0,0 +1,67 @@
|
||||
const commandLineArgs = require('command-line-args')
|
||||
, logger = require("logops");
|
||||
|
||||
class Config {
|
||||
|
||||
constructor() {
|
||||
this.options = {}
|
||||
this.requires = ['env', 'gateway', 'quix24']
|
||||
this.init()
|
||||
this.validate()
|
||||
this.finalize()
|
||||
}
|
||||
|
||||
init() {
|
||||
try {
|
||||
this.options = commandLineArgs([
|
||||
{ name: 'env', alias: 'e', type: String, defaultValue: ['production'] },
|
||||
{ name: 'host', type: String },
|
||||
{ name: 'port', type: Number },
|
||||
{ name: 'database', alias: 'd', type: String },
|
||||
{ name: 'username', alias: 'u', type: String },
|
||||
{ name: 'password', alias: 'p', type: String },
|
||||
{ name: 'mongo', alias: 'm', type: String },
|
||||
{ name: 'redis', alias: 'r', type: String },
|
||||
{ name: 'level', alias: 'l', type: String },
|
||||
{ name: 'gateway', alias: 'g', type: String },
|
||||
{ name: 'quix24', alias: 'q', type: String }
|
||||
]);
|
||||
} catch (e) {
|
||||
logger.debug('Command line arguments interpret failed :', e.message)
|
||||
logger.debug('expected arguments : ', JSON.stringify(this.requires))
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
finalize() {
|
||||
if (this.options.env == 'development') {
|
||||
this.options.level = this.options.level ? this.options.level : "DEBUG"
|
||||
logger.formatters.dev.omit = ['pid', 'port', 'hostname', 'app'];
|
||||
// logger.format = logger.formatters.dev;
|
||||
} else {
|
||||
this.options.level = this.options.level ? this.options.level : "WARN"
|
||||
}
|
||||
logger.formatters.json.omit = ['pid', 'port', 'hostname', 'app'];
|
||||
logger.setLevel(this.options.level)
|
||||
logger.debug(this.options, 'Environment setting options')
|
||||
}
|
||||
|
||||
validate() {
|
||||
for (let key in this.options) {
|
||||
if (this.options[key]) {
|
||||
delete this.requires[this.requires.indexOf(key)]
|
||||
}
|
||||
}
|
||||
this.requires = this.requires.filter(function (el) {
|
||||
return el != null;
|
||||
})
|
||||
if (this.requires.length) {
|
||||
logger.debug('Process terminated invalid required arguments: ', JSON.stringify(this.requires))
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
let config = new Config;
|
||||
module.exports = config.options
|
||||
65
config/website/Real.js
Normal file
65
config/website/Real.js
Normal file
@@ -0,0 +1,65 @@
|
||||
class Real {
|
||||
|
||||
constructor() {
|
||||
this.selectors = {
|
||||
title: '.rd-title',
|
||||
price: '.rd-buybox__price',
|
||||
main_image: '.rd-gallery__container--thumbnails .swiper-slide',
|
||||
// info_box: '.rd-product-description__top-accordion-content-attributes .rd-attribute-table > div',
|
||||
info_box: 'div.rd-product-description__top-accordion-content > div.rd-product-description__top-accordion-content-attributes .rd-attribute-table > div',
|
||||
// info_title: 'span.rd-product-description__attribute-title',
|
||||
info_title: '> span',
|
||||
// info_data: 'div.rd-product-description__attribute-values',
|
||||
info_data: 'div > div',
|
||||
description: '#rd-product-description',
|
||||
waitElements: []
|
||||
}
|
||||
this.selectors.waitElements.push(this.selectors.main_image)
|
||||
this.selectors.waitElements.push(this.selectors.info_box)
|
||||
}
|
||||
|
||||
extract($, cb) {
|
||||
let cleanup = (txt) => {
|
||||
return typeof txt == 'string' ? txt.replace(/[\-\t\n\r]+/g, '').replace(/[\s]{2}/g, '').trim() : txt
|
||||
}
|
||||
let info = {}
|
||||
$(this.selectors.info_box).map((k, el) => {
|
||||
let infoData = $(el).find(this.selectors.info_data).map((k, v) => {
|
||||
return cleanup($(v).text())
|
||||
}).get()
|
||||
info[$(el).find(this.selectors.info_title).text()] = cleanup(infoData.filter((item, index) => infoData.indexOf(item) === index).join(' | '))
|
||||
})
|
||||
|
||||
info = Object.assign({
|
||||
title: cleanup($(this.selectors.title).text()),
|
||||
price: cleanup($(this.selectors.price).text()).replace(',', '.') + ($(this.selectors.price).data('cents') ? cleanup($(this.selectors.price).data('cents')) : ''),
|
||||
main_img: (() => {
|
||||
let images = $(this.selectors.main_image)
|
||||
if (images.length) {
|
||||
images = images.map((k, v) => {
|
||||
// return $(v).css('background-image').slice(4, -1).replace(/"/g, "")
|
||||
return $(v).find('img').attr('src')
|
||||
}).get()
|
||||
} else {
|
||||
images = []
|
||||
let img = $('.rd-product-image-gallery__slide-large-image')
|
||||
if (img.length) images = [img.attr('src')]
|
||||
}
|
||||
return images.length ? images : null
|
||||
})()
|
||||
}, info)
|
||||
|
||||
$(this.selectors.description).find('*').each((k, elem) => this.removeAllAttributes($, elem))
|
||||
info.description = '<div>' + $(this.selectors.description).html() + '</div>'
|
||||
cb(info)
|
||||
}
|
||||
|
||||
removeAllAttributes = function ($, node) {
|
||||
node.attributes || Object.keys(node.attribs).map(
|
||||
name => $(node).removeAttr(name)
|
||||
);
|
||||
return node
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = new Real
|
||||
Reference in New Issue
Block a user