Commit e42429be by 马玮

Add customer to db

parent 5e22a2c1
...@@ -15,6 +15,12 @@ source /etc/profile ...@@ -15,6 +15,12 @@ source /etc/profile
sudo yum install redis sudo yum install redis
``` ```
## How to use
```
1.node accountTool.js -t saveAccount -d 1 -w autohome -u 河南明志汽车大迈8054 -p hnmz147852.
2.node boot.js -t fetchClues -T 1
```
## To do list: ## To do list:
- [x] 功能:根据环境变量读取配置 - [x] 功能:根据环境变量读取配置
- [x] 功能:集成若快验证码识别 - [x] 功能:集成若快验证码识别
...@@ -30,10 +36,10 @@ sudo yum install redis ...@@ -30,10 +36,10 @@ sudo yum install redis
- [ ] 功能:代理随机切换 - [ ] 功能:代理随机切换
- [ ] 功能:登录错误细分(密码错误、验证码错误等区分处理入库) - [ ] 功能:登录错误细分(密码错误、验证码错误等区分处理入库)
- [x] 功能:线索车型映射 - [x] 功能:线索车型映射
- [ ] 功能:线索顾客映射 - [x] 功能:线索顾客映射
- [ ] 功能:线索销售映射(不一定做) - [ ] 功能:线索销售映射(不一定做)
- [x] 功能:线索统计 - [x] 功能:线索统计
- [ ] 功能:生成账号记录命令行工具 - [x] 功能:生成账号记录命令行工具
- [ ] 功能:发现第三方车型和本地不匹配将未知车型入库方便开发爬取同步车型 - [ ] 功能:发现第三方车型和本地不匹配将未知车型入库方便开发爬取同步车型
- [ ] 功能:线索入库前对数据进行基础校验(如车型不匹配等如何处理) - [ ] 功能:线索入库前对数据进行基础校验(如车型不匹配等如何处理)
- [ ] 功能:Cluster分布式进程调度 - [ ] 功能:Cluster分布式进程调度
...@@ -42,6 +48,7 @@ sudo yum install redis ...@@ -42,6 +48,7 @@ sudo yum install redis
- [ ] 功能:增加测试用例和工具 - [ ] 功能:增加测试用例和工具
- [ ] 功能:通过环境变量设定根目录 - [ ] 功能:通过环境变量设定根目录
- [ ] 功能:抓取线索一半登录失效需要重新登录 - [ ] 功能:抓取线索一半登录失效需要重新登录
- [ ] 优化:所有forEach用for...of替换,对async/await友好
- [ ] 优化:cookie使用redis做一级缓存,缓存不存在时再从db读取 - [ ] 优化:cookie使用redis做一级缓存,缓存不存在时再从db读取
- [ ] 优化:整理所有错误,建立错误继承关系,区分操作错误和程序错误 - [ ] 优化:整理所有错误,建立错误继承关系,区分操作错误和程序错误
- [ ] 优化:易车抓取方式尝试破解request,phantomjs方案有点过于缓慢 - [ ] 优化:易车抓取方式尝试破解request,phantomjs方案有点过于缓慢
......
...@@ -9,7 +9,7 @@ const DealerHelper = require('./lib/helpers/Dealer'); ...@@ -9,7 +9,7 @@ const DealerHelper = require('./lib/helpers/Dealer');
program program
.version('0.1.0') .version('0.1.0')
.option('-t, --task <task name>', 'Task list: addAccount') .option('-t, --task <task name>', 'Task list: saveAccount')
.option('-d, --dealerID <thirdparty account ID>', 'Assign dealerID') .option('-d, --dealerID <thirdparty account ID>', 'Assign dealerID')
.option('-w, --website <thirdparty website>', 'Webname list: autohome, easypass') .option('-w, --website <thirdparty website>', 'Webname list: autohome, easypass')
.option('-u, --username <thirdparty username>', 'Assign username') .option('-u, --username <thirdparty username>', 'Assign username')
...@@ -32,7 +32,7 @@ if (!program.username) { ...@@ -32,7 +32,7 @@ if (!program.username) {
if (!program.password) { if (!program.password) {
commandError.push('缺少password!'); commandError.push('缺少password!');
} }
const validTasks = ['addAccount']; const validTasks = ['saveAccount'];
if (program.task && !validTasks.includes(program.task)) { if (program.task && !validTasks.includes(program.task)) {
commandError.push('网站类型不合法!'); commandError.push('网站类型不合法!');
} }
...@@ -49,10 +49,10 @@ if (commandError.length > 0) { ...@@ -49,10 +49,10 @@ if (commandError.length > 0) {
} }
(async () => { (async () => {
if (program.task === 'addAccount') { if (program.task === 'saveAccount') {
const success = await DealerHelper.addAccount(program); const accountID = await DealerHelper.saveAccount(program);
if (success === true) { if (accountID) {
console.log('账号添加成功!'); console.log(`账号添加成功!accountID: ${accountID}`);
} else { } else {
console.log('账号添加失败!'); console.log('账号添加失败!');
} }
......
...@@ -255,12 +255,13 @@ class Autohome { ...@@ -255,12 +255,13 @@ class Autohome {
clue.customerId = idMatch[1] || 0; clue.customerId = idMatch[1] || 0;
clue.customerName = (cheerio.load(l.CustomerNameStr).text() || '').trim(); clue.customerName = (cheerio.load(l.CustomerNameStr).text() || '').trim();
clue.customerPhone = (phoneAreaMatch[1] || '').trim(); clue.customerPhone = (phoneAreaMatch[1] || '').trim();
clue.customerArea = (phoneAreaMatch[2] || '').trim(); // clue.customerArea = (phoneAreaMatch[2] || '').replace(/\s+/g, '');
clue.salesmanName = (salesMatch[1] || '').trim(); clue.salesmanName = (salesMatch[1] || '').trim();
clue.salesPhone = (salesMatch[2] || '').trim(); clue.salesPhone = (salesMatch[2] || '').trim();
clue.orderType = l.OrderTypeStr.trim(); clue.orderType = l.OrderTypeStr.trim();
clue.orderState = l.OrderStateStr.trim(); clue.orderState = l.OrderStateStr.trim();
clue.licenseArea = l.LicenseCityStr.trim(); clue.licenseArea = l.LicenseCityStr.replace(/\s+/g, '');
clue.customerArea = clue.licenseArea;
clue.intentionDes = l.SpecNameStr.trim(); clue.intentionDes = l.SpecNameStr.trim();
clue.createdAt = l.LeadTimeStr.trim(); clue.createdAt = l.LeadTimeStr.trim();
clues.push(clue); clues.push(clue);
......
...@@ -227,7 +227,7 @@ class Easypass { ...@@ -227,7 +227,7 @@ class Easypass {
const nameAreaMatch = customerNameAreaStr.match(/(.*?)\[(.*?)\]/); const nameAreaMatch = customerNameAreaStr.match(/(.*?)\[(.*?)\]/);
clue.customerName = (nameAreaMatch[1] || '').trim(); clue.customerName = (nameAreaMatch[1] || '').trim();
clue.licenseArea = (nameAreaMatch[2] || '').trim(); clue.licenseArea = (nameAreaMatch[2] || '').replace(/\s+/g, '');
clue.customerArea = clue.licenseArea; clue.customerArea = clue.licenseArea;
clue.customerPhone = (ptitlePieces[1] || '').replace('电话', '').trim(); clue.customerPhone = (ptitlePieces[1] || '').replace('电话', '').trim();
clue.intentionDes = (ptitlePieces[2] || '').replace('订购', '').trim(); clue.intentionDes = (ptitlePieces[2] || '').replace('订购', '').trim();
......
...@@ -9,6 +9,46 @@ const day = moment().subtract(3, 'days').format('YYYY.MM.DD'); ...@@ -9,6 +9,46 @@ const day = moment().subtract(3, 'days').format('YYYY.MM.DD');
const axios = require('axios'); const axios = require('axios');
const config = require('config'); const config = require('config');
async function test (l) {
await Promise.delay(l*1000).then(async function() {
console.log('过了' + l + '秒');
console.log((new Date()).toLocaleString());
console.log('=======================================');
});
}
(async () => {
console.log((new Date()).toDateString());
// const global_var = '全局变量';
// const test_fun = () => {
// console.log(global_var);
// }
// test_fun();
let list = [1, 2, 3, 4, 5];
for (l of list) {
console.log((new Date()).toLocaleString());
await test(l);
}
})();
return;
function testCatch() {
return new Promise(async (resolve, reject) => {
try {
throw new Error('傻B');
} catch (e) {
console.log('拒绝', e);
reject(e);
} finally {
console.log('finally');
}
});
}
testCatch().catch((e) => {
console.log('逮到你喽', e);
});
return;
const updatedAt = moment().format('YYYY-MM-DD HH:mm:ss'); const updatedAt = moment().format('YYYY-MM-DD HH:mm:ss');
console.log(moment('2017-08-09 09:56').format('X')); console.log(moment('2017-08-09 09:56').format('X'));
return; return;
...@@ -202,26 +242,4 @@ const testHorseman = async () => { ...@@ -202,26 +242,4 @@ const testHorseman = async () => {
// console.log((new Date()).toLocaleString()); // console.log((new Date()).toLocaleString());
// }) // })
.close(); .close();
} }
\ No newline at end of file
async function test (l) {
await Promise.delay(l*1000).then(async function() {
console.log('过了' + l + '秒');
console.log((new Date()).toLocaleString());
console.log('=======================================');
});
}
(async () => {
console.log((new Date()).toDateString());
// const global_var = '全局变量';
// const test_fun = () => {
// console.log(global_var);
// }
// test_fun();
let list = [1, 2, 3, 4, 5];
for (l of list) {
console.log((new Date()).toLocaleString());
await test(l);
}
})();
\ No newline at end of file
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