Commit 002c411a by 马玮

Change config style

parent 5428dec9
...@@ -22,7 +22,7 @@ const spider = new Spider({ ...@@ -22,7 +22,7 @@ const spider = new Spider({
userid : program.userid, userid : program.userid,
task : program.task, task : program.task,
webname : program.webname, webname : program.webname,
username : dealerWebInfo.USERNAME, username : dealerWebInfo.username,
password : dealerWebInfo.PASSWORD password : dealerWebInfo.password
}); });
spider.execute(); spider.execute();
\ No newline at end of file
[DMT] [dmt]
ID = 48793 id = 48793
KEY = "c6c1bb5ea2c8f3706ed531c6cb5169cb" key = 'c6c1bb5ea2c8f3706ed531c6cb5169cb'
HOST = "http://api.dama2.com:7766/app/" host = 'http://api.dama2.com:7766/app/'
USER = "test" user = 'test'
PWD = "test" pwd = 'test'
[DEALER.AUTOIFENG] [dealer.autoifeng]
USERNAME = "上海车城汽车" username = '上海车城汽车'
PASSWORD = "Checheng235#" password = 'Checheng235#'
CAPTCHA_TYPE = "FOUR_CHARACTERS" captcha_type = 'four_characters'
[DEALER.EASYPASS] [dealer.easypass]
USERNAME = "100074110" username = '100074110'
PASSWORD = "hnmz147852." password = 'hnmz147852.'
CAPTCHA_TYPE = "ARITHMETIC" captcha_type = 'arithmetic'
[DEALER.AUTOHOME] [dealer.autohome]
USERNAME = "河南明志汽车大迈8054" username = '河南明志汽车大迈8054'
PASSWORD = "hnmz147852." password = 'hnmz147852.'
CAPTCHA_TYPE = "FOUR_LETTERS" captcha_type = 'four_letters'
[CAPTCHA.RUOKUAI] [captcha.ruokuai]
USERNAME = "chedev" username = 'chedev'
PASSWORD = "Checheng235#" password = 'Checheng235#'
SOFTID = 86134 softid = 86134
SOFTKEY = "b167ed636a224990a2f04ae2d28d1542" softkey = 'b167ed636a224990a2f04ae2d28d1542'
[CAPTCHA.RUOKUAI.TYPEIDS] [captcha.ruokuai.typeids]
FOUR_LETTERS = 2040 # 四个英文字母 four_letters = 2040 # 四个英文字母
FOUR_CHARACTERS = 3040 # 四个字母数字混合 four_characters = 3040 # 四个字母数字混合
ARITHMETIC = 7100 # 算术题 arithmetic = 7100 # 算术题
[DB.MASTER] [db.master]
HOST = 'localhost' host = 'localhost'
PORT = 3306 port = 3306
USER = 'root' user = 'root'
PASSWORD = 'root' password = 'root'
DATABASE = 'test' database = 'test'
[db] [testing]
a = 1 \ No newline at end of file
\ No newline at end of file
...@@ -6,7 +6,7 @@ const captcha = exports; ...@@ -6,7 +6,7 @@ const captcha = exports;
captcha.decode = async (captchaType, imageFile) => { captcha.decode = async (captchaType, imageFile) => {
console.info('captchaType:', captchaType); console.info('captchaType:', captchaType);
console.info('imageFile:', imageFile); console.info('imageFile:', imageFile);
const typeids = config.get('CAPTCHA.RUOKUAI.TYPEIDS'); const typeids = config.get('captcha.ruokuai.typeids');
typeid = typeids[captchaType]; typeid = typeids[captchaType];
const captchaText = ruokuai.decode(typeid, imageFile); const captchaText = ruokuai.decode(typeid, imageFile);
return captchaText; return captchaText;
...@@ -19,13 +19,9 @@ captcha.decodeBase64 = async (captchaType, base64Text) => { ...@@ -19,13 +19,9 @@ captcha.decodeBase64 = async (captchaType, base64Text) => {
// data:image/png;base64, + base64Text // data:image/png;base64, + base64Text
writeStream.write(base64Text, 'base64'); writeStream.write(base64Text, 'base64');
console.info('captchaType:', captchaType);
console.info('imageFile:', imageFile);
if (fs.existsSync(imageFile) && fs.statSync(imageFile).isFile()) { if (fs.existsSync(imageFile) && fs.statSync(imageFile).isFile()) {
const typeids = config.get('CAPTCHA.RUOKUAI.TYPEIDS'); const captchaText = this.decode(captchaType, imageFile);
typeid = typeids[captchaType]; fs.unlinkSync(imageFile);
const captchaText = ruokuai.decode(typeid, imageFile);
// fs.unlinkSync(imageFile);
return captchaText; return captchaText;
} else { } else {
throw new Error(`${imageFile} is not a file`); throw new Error(`${imageFile} is not a file`);
......
...@@ -10,13 +10,13 @@ const errors = require('../errors'); ...@@ -10,13 +10,13 @@ const errors = require('../errors');
const ruokuai = exports; const ruokuai = exports;
ruokuai.decode = async (typeid, imageFile) => { ruokuai.decode = async (typeid, imageFile) => {
const ruokuaiInfo = config.get('CAPTCHA.RUOKUAI'); const ruokuaiInfo = config.get('captcha.ruokuai');
const formData = new FormData(); const formData = new FormData();
formData.append('username', ruokuaiInfo.USERNAME); formData.append('username', ruokuaiInfo.username);
formData.append('password', ruokuaiInfo.PASSWORD); formData.append('password', ruokuaiInfo.password);
formData.append('softid', ruokuaiInfo.SOFTID); formData.append('softid', ruokuaiInfo.softid);
formData.append('softkey', ruokuaiInfo.SOFTKEY); formData.append('softkey', ruokuaiInfo.softkey);
formData.append('typeid', typeid); formData.append('typeid', typeid);
formData.append("image", fs.createReadStream(imageFile), imageFile); formData.append("image", fs.createReadStream(imageFile), imageFile);
......
...@@ -7,23 +7,17 @@ const clusterConfig = { ...@@ -7,23 +7,17 @@ const clusterConfig = {
defaultSelector: 'RR' defaultSelector: 'RR'
}; };
const poolCluster = mysql.createPoolCluster(clusterConfig); const poolCluster = mysql.createPoolCluster(clusterConfig);
const db = config.get('DB'); const db = config.get('db');
for (let [nodeId, nodeConfig] of Object.entries(db)) { for (let [nodeId, nodeConfig] of Object.entries(db)) {
console.log(nodeConfig); console.log(nodeConfig);
poolCluster.add(nodeId, { poolCluster.add(nodeId, nodeConfig);
host: nodeConfig.HOST,
port: nodeConfig.PORT,
user: nodeConfig.USER,
password: nodeConfig.PASSWORD,
database: nodeConfig.DATABASE
});
} }
module.exports = poolCluster; module.exports = poolCluster;
poolCluster.getConnection('MASTER', function (err, connection) { poolCluster.getConnection('MASTER', function (err, connection) {
connection.query( connection.query(
'SELECT * FROM `test` WHERE `id` > 1', 'SELECT * FROM test2.`test` WHERE `id` > 1',
function(err, results, fields) { function(err, results, fields) {
console.log(results); // results contains rows returned by server console.log(results); // results contains rows returned by server
// console.log(fields); // fields contains extra meta data about results, if available // console.log(fields); // fields contains extra meta data about results, if available
......
...@@ -7,17 +7,11 @@ const clusterConfig = { ...@@ -7,17 +7,11 @@ const clusterConfig = {
defaultSelector: 'RR' defaultSelector: 'RR'
}; };
const poolCluster = mysql.createPoolCluster(clusterConfig); const poolCluster = mysql.createPoolCluster(clusterConfig);
const db = config.get('DB'); const db = config.get('db');
for (let [nodeId, nodeConfig] of Object.entries(db)) { for (let [nodeId, nodeConfig] of Object.entries(db)) {
console.log(nodeConfig); console.log(nodeConfig);
poolCluster.add(nodeId, { poolCluster.add(nodeId, nodeConfig);
host: nodeConfig.HOST,
port: nodeConfig.PORT,
user: nodeConfig.USER,
password: nodeConfig.PASSWORD,
database: nodeConfig.DATABASE
});
} }
module.exports = poolCluster; module.exports = poolCluster;
...@@ -62,7 +62,7 @@ class DealerHelper { ...@@ -62,7 +62,7 @@ class DealerHelper {
throw errors.AppError('Params missing'); 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 updated_at = moment().format('YYYY-MM-DD HH:mm:ss');
const valuesSql = []; const valuesSql = [];
const _clue = { 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'; 'use strict';
const AutoHome = require('./AutoHome'); const Autohome = require('./Autohome');
const EasyPass = require('./EasyPass'); const Easypass = require('./Easypass');
// TODO: someday will finish this module // TODO: someday will finish this module
// const AutoIfeng = require('./AutoIfeng'); // const AutoIfeng = require('./AutoIfeng');
exports.AutoHome = AutoHome; exports.Autohome = Autohome;
exports.EasyPass = EasyPass; exports.Easypass = Easypass;
// exports.AutoIfeng = AutoIfeng; // exports.AutoIfeng = AutoIfeng;
\ No newline at end of file
...@@ -12,16 +12,16 @@ class Spider { ...@@ -12,16 +12,16 @@ class Spider {
getSpider() { getSpider() {
let spider; let spider;
switch (this.params.webname) { switch (this.params.webname) {
case 'DEALER.AUTOIFENG': { case 'dealer.autoifeng': {
spider = new dealer.AutoIfeng(this.params); spider = new dealer.AutoIfeng(this.params);
break; break;
} }
case 'DEALER.AUTOHOME': { case 'dealer.autohome': {
spider = new dealer.AutoHome(this.params); spider = new dealer.Autohome(this.params);
break; break;
} }
case 'DEALER.EASYPASS': { case 'dealer.easypass': {
spider = new dealer.EasyPass(this.params); spider = new dealer.Easypass(this.params);
break; 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