Skip to content

Commit

Permalink
Fix SZ market insider trading query
Browse files Browse the repository at this point in the history
  • Loading branch information
topdna committed Apr 29, 2016
1 parent a315729 commit 0dec325
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions lib/insider.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
* 上海主板高管持股变动: http://www.sse.com.cn/disclosure/listedinfo/credibility/change/
*/

let async = require('async'),
let vm = require('vm'),
async = require('async'),
_ = require('lodash'),
moment = require('moment'),
cheerio = require('cheerio'),
Expand Down Expand Up @@ -177,23 +178,21 @@ let displayMiscSummary = function displayMiscSummary(summary){
* @return {Object} Promise of total trading count.
*/
let getSzPagingInfo = function getSzPagingInfo(html){

let $ = cheerio.load(html, { decodeEntities:false });
let text = _.trim($('td[colspan="12"]',this).text());
if(text === MSG.NO_DATA_FROM_SZ){ return { totalPg: 0, totalCount: 0 }; }

let pgUrlNext = $('input.cls-navigate-next', this).attr('onclick') || '';
let pgUrlPrev = $('input.cls-navigate-prev', this).attr('onclick') || '';
if(!pgUrlNext && !pgUrlPrev) { return { totalPg:1, totalCount: $('tr.cls-data-tr', this).length }; }
let nextFn = $('input.cls-navigate-next', this).attr('onclick')||'';
let prevFn = $('input.cls-navigate-prev', this).attr('onclick')||'';
if(!nextFn && !prevFn) { return { totalPg:1, totalCount: $('tr.cls-data-tr', this).length }; }

let pgIdxNext = pgUrlNext.indexOf('&tab1PAGECOUNT=') + '&tab1PAGECOUNT='.length;
let pgIdxPrev = pgUrlPrev.indexOf('&tab1PAGECOUNT=') + '&tab1PAGECOUNT='.length;
let totalSzPg = _.parseInt(pgUrlNext.substr(pgIdxNext)) || _.parseInt(pgUrlPrev.substr(pgIdxPrev));
// gotoReportPageNo('1801_nm','tab1',2,584,11670)
global.gotoReportPageNo = (mkt, id, nIdx, totalPg, totalCount) => [totalPg, totalCount];

let totalIdxNext = pgUrlNext.indexOf('&tab1RECORDCOUNT=') + '&tab1RECORDCOUNT='.length;
let totalIdxPrev = pgUrlPrev.indexOf('&tab1RECORDCOUNT=') + '&tab1RECORDCOUNT='.length;
let totalCount = _.parseInt(pgUrlNext.substr(totalIdxNext)) || _.parseInt(pgUrlPrev.substr(totalIdxPrev));
let pgInfo = vm.runInThisContext(nextFn||prevFn);

return { totalPg: totalSzPg, totalCount };
return {totalPg:pgInfo[0], totalCount:pgInfo[1]};
};

/**
Expand Down

0 comments on commit 0dec325

Please sign in to comment.