...
|
...
|
@@ -10,7 +10,7 @@ const logger = global.yoho.logger; |
|
|
const helper = global.yoho.helpers;
|
|
|
const config = require('../config/config');
|
|
|
const qs = require('querystring');
|
|
|
|
|
|
const fs = require('fs');
|
|
|
|
|
|
/**
|
|
|
* redis multi command
|
...
|
...
|
@@ -141,10 +141,11 @@ const sendUrls = () => { |
|
|
/**
|
|
|
* 调用接口建议词
|
|
|
*/
|
|
|
const getKeywordsApi = (page, limit) => {
|
|
|
const getKeywordsApi = (page, limit, count) => {
|
|
|
let params = {
|
|
|
page: page || 1,
|
|
|
limit: limit || 1000,
|
|
|
count: count || 6,
|
|
|
method: 'web.search.suggestList'
|
|
|
};
|
|
|
|
...
|
...
|
@@ -180,8 +181,12 @@ const synchronousKeywords = () => { |
|
|
|
|
|
start += limit;
|
|
|
page++;
|
|
|
console.log(page);
|
|
|
_.forEach(_.get(result, 'data.suggest_list', []), value => {
|
|
|
value.keyword = value.keyword.split(' ').join('');
|
|
|
if (value.keyword.length <= 2) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
let key = `keywords_mana:${value.keyword}`;
|
|
|
|
|
|
multi.set(key, value.keyword);
|
...
|
...
|
@@ -199,6 +204,15 @@ const synchronousKeywords = () => { |
|
|
});
|
|
|
};
|
|
|
|
|
|
// 纪录关键词
|
|
|
const writeFile = (file, str) => {
|
|
|
fs.appendFile(file, `${str}\n`, function(err) {
|
|
|
if (err) {
|
|
|
logger.info(err);
|
|
|
}
|
|
|
});
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 查询 redis中 关键词
|
|
|
* @type {{getKeyWordsUrl}}
|
...
|
...
|
@@ -209,8 +223,12 @@ const getRedisKeywords = (start, end) => { |
|
|
let urls = {pc: [], wap: []};
|
|
|
|
|
|
_.forEach(res, keyword => {
|
|
|
let buff = new Buffer(keyword.replace('keywords_mana:', '')).toString('hex').toUpperCase();
|
|
|
keyword = keyword.replace('keywords_mana:', '');
|
|
|
let buff = new Buffer(keyword).toString('hex').toUpperCase();
|
|
|
|
|
|
writeFile(`./logs/keywords_${helper.dateFormat('YYYY-MM-DD H', new Date())}.log`, `${keyword} https://www.yohobuy.com/so/${buff}.html`);
|
|
|
|
|
|
// TODO 纪录已经推送的关键词
|
|
|
urls.pc.push(`https://www.yohobuy.com/so/${buff}.html`);
|
|
|
urls.wap.push(`https://m.yohobuy.com/so/${buff}.html`);
|
|
|
});
|
...
|
...
|
|