Commit 002c411a by 马玮

Change config style

parent 5428dec9
......@@ -22,7 +22,7 @@ const spider = new Spider({
userid : program.userid,
task : program.task,
webname : program.webname,
username : dealerWebInfo.USERNAME,
password : dealerWebInfo.PASSWORD
username : dealerWebInfo.username,
password : dealerWebInfo.password
});
spider.execute();
\ No newline at end of file
[DMT]
ID = 48793
KEY = "c6c1bb5ea2c8f3706ed531c6cb5169cb"
HOST = "http://api.dama2.com:7766/app/"
USER = "test"
PWD = "test"
[dmt]
id = 48793
key = 'c6c1bb5ea2c8f3706ed531c6cb5169cb'
host = 'http://api.dama2.com:7766/app/'
user = 'test'
pwd = 'test'
[DEALER.AUTOIFENG]
USERNAME = "上海车城汽车"
PASSWORD = "Checheng235#"
CAPTCHA_TYPE = "FOUR_CHARACTERS"
[dealer.autoifeng]
username = '上海车城汽车'
password = 'Checheng235#'
captcha_type = 'four_characters'
[DEALER.EASYPASS]
USERNAME = "100074110"
PASSWORD = "hnmz147852."
CAPTCHA_TYPE = "ARITHMETIC"
[dealer.easypass]
username = '100074110'
password = 'hnmz147852.'
captcha_type = 'arithmetic'
[DEALER.AUTOHOME]
USERNAME = "河南明志汽车大迈8054"
PASSWORD = "hnmz147852."
CAPTCHA_TYPE = "FOUR_LETTERS"
[dealer.autohome]
username = '河南明志汽车大迈8054'
password = 'hnmz147852.'
captcha_type = 'four_letters'
[CAPTCHA.RUOKUAI]
USERNAME = "chedev"
PASSWORD = "Checheng235#"
SOFTID = 86134
SOFTKEY = "b167ed636a224990a2f04ae2d28d1542"
[captcha.ruokuai]
username = 'chedev'
password = 'Checheng235#'
softid = 86134
softkey = 'b167ed636a224990a2f04ae2d28d1542'
[CAPTCHA.RUOKUAI.TYPEIDS]
FOUR_LETTERS = 2040 # 四个英文字母
FOUR_CHARACTERS = 3040 # 四个字母数字混合
ARITHMETIC = 7100 # 算术题
[captcha.ruokuai.typeids]
four_letters = 2040 # 四个英文字母
four_characters = 3040 # 四个字母数字混合
arithmetic = 7100 # 算术题
[DB.MASTER]
HOST = 'localhost'
PORT = 3306
USER = 'root'
PASSWORD = 'root'
DATABASE = 'test'
[db.master]
host = 'localhost'
port = 3306
user = 'root'
password = 'root'
database = 'test'
[db]
a = 1
\ No newline at end of file
[testing]
\ No newline at end of file
......@@ -6,7 +6,7 @@ const captcha = exports;
captcha.decode = async (captchaType, imageFile) => {
console.info('captchaType:', captchaType);
console.info('imageFile:', imageFile);
const typeids = config.get('CAPTCHA.RUOKUAI.TYPEIDS');
const typeids = config.get('captcha.ruokuai.typeids');
typeid = typeids[captchaType];
const captchaText = ruokuai.decode(typeid, imageFile);
return captchaText;
......@@ -19,13 +19,9 @@ captcha.decodeBase64 = async (captchaType, base64Text) => {
// data:image/png;base64, + base64Text
writeStream.write(base64Text, 'base64');
console.info('captchaType:', captchaType);
console.info('imageFile:', imageFile);
if (fs.existsSync(imageFile) && fs.statSync(imageFile).isFile()) {
const typeids = config.get('CAPTCHA.RUOKUAI.TYPEIDS');
typeid = typeids[captchaType];
const captchaText = ruokuai.decode(typeid, imageFile);
// fs.unlinkSync(imageFile);
const captchaText = this.decode(captchaType, imageFile);
fs.unlinkSync(imageFile);
return captchaText;
} else {
throw new Error(`${imageFile} is not a file`);
......
......@@ -10,13 +10,13 @@ const errors = require('../errors');
const ruokuai = exports;
ruokuai.decode = async (typeid, imageFile) => {
const ruokuaiInfo = config.get('CAPTCHA.RUOKUAI');
const ruokuaiInfo = config.get('captcha.ruokuai');
const formData = new FormData();
formData.append('username', ruokuaiInfo.USERNAME);
formData.append('password', ruokuaiInfo.PASSWORD);
formData.append('softid', ruokuaiInfo.SOFTID);
formData.append('softkey', ruokuaiInfo.SOFTKEY);
formData.append('username', ruokuaiInfo.username);
formData.append('password', ruokuaiInfo.password);
formData.append('softid', ruokuaiInfo.softid);
formData.append('softkey', ruokuaiInfo.softkey);
formData.append('typeid', typeid);
formData.append("image", fs.createReadStream(imageFile), imageFile);
......
......@@ -7,23 +7,17 @@ const clusterConfig = {
defaultSelector: 'RR'
};
const poolCluster = mysql.createPoolCluster(clusterConfig);
const db = config.get('DB');
const db = config.get('db');
for (let [nodeId, nodeConfig] of Object.entries(db)) {
console.log(nodeConfig);
poolCluster.add(nodeId, {
host: nodeConfig.HOST,
port: nodeConfig.PORT,
user: nodeConfig.USER,
password: nodeConfig.PASSWORD,
database: nodeConfig.DATABASE
});
poolCluster.add(nodeId, nodeConfig);
}
module.exports = poolCluster;
poolCluster.getConnection('MASTER', function (err, connection) {
connection.query(
'SELECT * FROM `test` WHERE `id` > 1',
'SELECT * FROM test2.`test` WHERE `id` > 1',
function(err, results, fields) {
console.log(results); // results contains rows returned by server
// console.log(fields); // fields contains extra meta data about results, if available
......
......@@ -7,17 +7,11 @@ const clusterConfig = {
defaultSelector: 'RR'
};
const poolCluster = mysql.createPoolCluster(clusterConfig);
const db = config.get('DB');
const db = config.get('db');
for (let [nodeId, nodeConfig] of Object.entries(db)) {
console.log(nodeConfig);
poolCluster.add(nodeId, {
host: nodeConfig.HOST,
port: nodeConfig.PORT,
user: nodeConfig.USER,
password: nodeConfig.PASSWORD,
database: nodeConfig.DATABASE
});
poolCluster.add(nodeId, nodeConfig);
}
module.exports = poolCluster;
......@@ -62,7 +62,7 @@ class DealerHelper {
throw errors.AppError('Params missing');
}
poolCluster.getConnection('MASTER', function (err, connection) {
poolCluster.getConnection('master', function (err, connection) {
const updated_at = moment().format('YYYY-MM-DD HH:mm:ss');
const valuesSql = [];
const _clue = {
......
'use strict';
const phantom = require('phantom');
const cheerio = require('cheerio');
class AutoIfeng {
constructor(params) {
this.params = params;
console.log(params);
}
execute() {
return new Promise((resolve, reject) => {
switch (this.params.task) {
case 'login': {
console.log('do login');
this.login();
break;
}
case 'tryLogin': {
break;
}
}
});
}
async login() {
const passport = this.params.username;
const password = this.params.password;
const instance = await phantom.create(['--ignore-ssl-errors=yes']);
const page = await instance.createPage();
page.property('viewportSize', {width: 1920, height: 1080});
await page.on("onResourceRequested", function(requestData) {
console.info('Requesting', requestData.url)
});
const status = await page.open('http://dealer.auto.ifeng.com/dealerback/dealerIndexPage');
console.log(status);
console.log(passport);
page.evaluate(function(passport, password) {
document.querySelector('input[id=passport]').value = passport;
document.querySelector('input[id=password]').value = password;
}).then(function(html) {
console.log(html);
});
const content = await page.property('content');
const $ = cheerio.load(content)
console.log('倒霉');
await page.render('m2.png');
await instance.exit();
}
}
module.exports = AutoIfeng;
\ No newline at end of file
'use strict';
const AutoHome = require('./AutoHome');
const EasyPass = require('./EasyPass');
const Autohome = require('./Autohome');
const Easypass = require('./Easypass');
// TODO: someday will finish this module
// const AutoIfeng = require('./AutoIfeng');
exports.AutoHome = AutoHome;
exports.EasyPass = EasyPass;
exports.Autohome = Autohome;
exports.Easypass = Easypass;
// exports.AutoIfeng = AutoIfeng;
\ No newline at end of file
......@@ -12,16 +12,16 @@ class Spider {
getSpider() {
let spider;
switch (this.params.webname) {
case 'DEALER.AUTOIFENG': {
case 'dealer.autoifeng': {
spider = new dealer.AutoIfeng(this.params);
break;
}
case 'DEALER.AUTOHOME': {
spider = new dealer.AutoHome(this.params);
case 'dealer.autohome': {
spider = new dealer.Autohome(this.params);
break;
}
case 'DEALER.EASYPASS': {
spider = new dealer.EasyPass(this.params);
case 'dealer.easypass': {
spider = new dealer.Easypass(this.params);
break;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment