Commit 3068ec8c by 马玮

Change random api

parent e14bd056
......@@ -6,7 +6,6 @@ const config = require('config');
const cheerio = require('cheerio');
const Horseman = require('node-horseman');
const moment = require('moment');
var randomInt = require('random-int');
const axios = require('axios');
// 自定义模块
const _ = require('../../utils/lodash');
......@@ -27,7 +26,7 @@ class Autohome extends Base {
async tryLogin() {
// 随机返回登录状态
// return [new errors.TryLoginError('登录失效'), randomInt(0, 1)];
// return [new errors.TryLoginError('登录失效'), _.random(0, 1)];
try {
let newCookies;
let oldCookies;
......@@ -79,7 +78,7 @@ class Autohome extends Base {
async login() {
// 随机返回登录状态
// return [new errors.LoginError('登录失败'), randomInt(0, 1)];
// return [new errors.LoginError('登录失败'), _.random(0, 1)];
try {
logger.info(`accountID: ${this.params.accountID}, 开始表单登录`);
......@@ -292,7 +291,7 @@ class Autohome extends Base {
// 判断是否抓取完全
if (customerIndex < rowCount) {
let randomSecs = randomInt(1, 5);
let randomSecs = _.random(1, 5);
logger.info(`accountID: ${this.params.accountID}, 随机等待${randomSecs}秒`);
await Promise.delay(randomSecs*1000).then(async function() {
params.pageIndex += 1;
......
......@@ -6,7 +6,6 @@ const config = require('config');
const cheerio = require('cheerio');
const Horseman = require('node-horseman');
const moment = require('moment');
var randomInt = require('random-int');
const axios = require('axios');
// 自定义模块
const _ = require('../../utils/lodash');
......@@ -28,7 +27,7 @@ class Easypass extends Base {
async tryLogin() {
// 随机返回登录状态
// return [new errors.TryLoginError('登录失效'), randomInt(0, 1)];
// return [new errors.TryLoginError('登录失效'), _.random(0, 1)];
let newCookies;
let oldCookies;
let loginStatus = false;
......@@ -77,8 +76,8 @@ class Easypass extends Base {
async login() {
// 随机返回登录状态
// return randomInt(0, 1);
// return [new errors.LoginError('登录失败'), randomInt(0, 1)];
// return _.random(0, 1);
// return [new errors.LoginError('登录失败'), _.random(0, 1)];
logger.info(`accountID: ${this.params.accountID}, 开始表单登录`);
const username = this.params.username;
......@@ -295,7 +294,7 @@ class Easypass extends Base {
await horseman.screenshot(`${__basedir}/tmp/workflow/${this.params.website}/nextPage.png`);
}
let randomSecs = randomInt(1, 5);
let randomSecs = _.random(1, 5);
logger.info(`accountID: ${this.params.accountID}, 随机等待${randomSecs}秒`);
await Promise.delay(randomSecs*1000).then(async function() {
await fetchByPage();
......
'use strict';
exports.pick = require('lodash.pick');
exports.assign = require('lodash.assign');
\ No newline at end of file
exports.pick = require('lodash/pick');
exports.assign = require('lodash/assign');
exports.random = require('lodash/random');
\ No newline at end of file
const Promise = require('bluebird');
var utils = require('./lib/utils');
const utils = require('./lib/utils');
const _ = require('./lib/utils/lodash');
console.log(_.random(1, 5));
console.log(_.random(1, 5));
console.log(_.random(1, 5));
console.log(utils.md5('欢迎来到王者荣耀'));
return;
// const DI = require('./lib/DI');
// process.env.NODE_ENV = process.env.NODE_ENV || 'production';
// process.env.NODE_CONFIG_DIR = __dirname + '/config';
......
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