Merge branch 'feature/keywordsUrl'
Showing
1 changed file
with
22 additions
and
4 deletions
@@ -10,7 +10,7 @@ const logger = global.yoho.logger; | @@ -10,7 +10,7 @@ const logger = global.yoho.logger; | ||
10 | const helper = global.yoho.helpers; | 10 | const helper = global.yoho.helpers; |
11 | const config = require('../config/config'); | 11 | const config = require('../config/config'); |
12 | const qs = require('querystring'); | 12 | const qs = require('querystring'); |
13 | - | 13 | +const fs = require('fs'); |
14 | 14 | ||
15 | /** | 15 | /** |
16 | * redis multi command | 16 | * redis multi command |
@@ -141,10 +141,11 @@ const sendUrls = () => { | @@ -141,10 +141,11 @@ const sendUrls = () => { | ||
141 | /** | 141 | /** |
142 | * 调用接口建议词 | 142 | * 调用接口建议词 |
143 | */ | 143 | */ |
144 | -const getKeywordsApi = (page, limit) => { | 144 | +const getKeywordsApi = (page, limit, count) => { |
145 | let params = { | 145 | let params = { |
146 | page: page || 1, | 146 | page: page || 1, |
147 | limit: limit || 1000, | 147 | limit: limit || 1000, |
148 | + count: count || 6, | ||
148 | method: 'web.search.suggestList' | 149 | method: 'web.search.suggestList' |
149 | }; | 150 | }; |
150 | 151 | ||
@@ -180,8 +181,12 @@ const synchronousKeywords = () => { | @@ -180,8 +181,12 @@ const synchronousKeywords = () => { | ||
180 | 181 | ||
181 | start += limit; | 182 | start += limit; |
182 | page++; | 183 | page++; |
183 | - console.log(page); | ||
184 | _.forEach(_.get(result, 'data.suggest_list', []), value => { | 184 | _.forEach(_.get(result, 'data.suggest_list', []), value => { |
185 | + value.keyword = value.keyword.split(' ').join(''); | ||
186 | + if (value.keyword.length <= 2) { | ||
187 | + return; | ||
188 | + } | ||
189 | + | ||
185 | let key = `keywords_mana:${value.keyword}`; | 190 | let key = `keywords_mana:${value.keyword}`; |
186 | 191 | ||
187 | multi.set(key, value.keyword); | 192 | multi.set(key, value.keyword); |
@@ -199,6 +204,15 @@ const synchronousKeywords = () => { | @@ -199,6 +204,15 @@ const synchronousKeywords = () => { | ||
199 | }); | 204 | }); |
200 | }; | 205 | }; |
201 | 206 | ||
207 | +// 纪录关键词 | ||
208 | +const writeFile = (file, str) => { | ||
209 | + fs.appendFile(file, `${str}\n`, function(err) { | ||
210 | + if (err) { | ||
211 | + logger.info(err); | ||
212 | + } | ||
213 | + }); | ||
214 | +}; | ||
215 | + | ||
202 | /** | 216 | /** |
203 | * 查询 redis中 关键词 | 217 | * 查询 redis中 关键词 |
204 | * @type {{getKeyWordsUrl}} | 218 | * @type {{getKeyWordsUrl}} |
@@ -209,8 +223,12 @@ const getRedisKeywords = (start, end) => { | @@ -209,8 +223,12 @@ const getRedisKeywords = (start, end) => { | ||
209 | let urls = {pc: [], wap: []}; | 223 | let urls = {pc: [], wap: []}; |
210 | 224 | ||
211 | _.forEach(res, keyword => { | 225 | _.forEach(res, keyword => { |
212 | - let buff = new Buffer(keyword.replace('keywords_mana:', '')).toString('hex').toUpperCase(); | 226 | + keyword = keyword.replace('keywords_mana:', ''); |
227 | + let buff = new Buffer(keyword).toString('hex').toUpperCase(); | ||
228 | + | ||
229 | + writeFile(`./logs/keywords_${helper.dateFormat('YYYY-MM-DD H', new Date())}.log`, `${keyword} https://www.yohobuy.com/so/${buff}.html`); | ||
213 | 230 | ||
231 | + // TODO 纪录已经推送的关键词 | ||
214 | urls.pc.push(`https://www.yohobuy.com/so/${buff}.html`); | 232 | urls.pc.push(`https://www.yohobuy.com/so/${buff}.html`); |
215 | urls.wap.push(`https://m.yohobuy.com/so/${buff}.html`); | 233 | urls.wap.push(`https://m.yohobuy.com/so/${buff}.html`); |
216 | }); | 234 | }); |
-
Please register or login to post a comment