function mcx_Future_IndexHistory(count,n,baseurl,downloadpath,unzippath,outputpath,logpath,fromd,tod,sn)
{
try
{
var mon=count[0].split('-')[0];
var m1=count[0].split('-')[1];
var d=count[0].split('-')[2];
var yy=count[0].split('-')[3];
var y=yy.substr(2,2);
var endmon=count[count.length-1].split('-')[0];
var endm1=count[count.length-1].split('-')[1];
var endd=count[count.length-1].split('-')[2];
var endyy=count[count.length-1].split('-')[3];
var y=endyy.substr(2,2);
var intMonth =getMonth(mon);
var endintMonth =getMonth(endmon);
var startDateForDownloadMCXFutureIndexHistory = intMonth+'/'+d+'/'+yy;
var endDateForDownloadMCXFutureIndexHistory = endintMonth+'/'+endd+'/'+endyy;
var strFileNameIndexHistory = intMonth+''+d+''+yy+'_to_'+endintMonth+''+endd+''+endyy;
var arrIndexValues = ['323','324','325','326'];
var arrSpotIndexValues = ['327','328','329','330'];
startProcessForMCXFutureIndexHistory(arrSpotIndexValues, arrIndexValues, startDateForDownloadMCXFutureIndexHistory, endDateForDownloadMCXFutureIndexHistory, outputpath, 0, strFileNameIndexHistory);
visit('indices.html');
function startProcessForMCXFutureIndexHistory(arrSpotIndexValues, arrIndexValues, startDateForDownloadMCXFutureIndexHistory, endDateForDownloadMCXFutureIndexHistory, outputpath, n, strFileNameIndexHistory)
{
try
{
document.getElementById("om").innerHTML+="<br/>MCXIndex"+arrIndexValues[n]+".csv is downloading";
fs = require('fs');
var csv = require('ya-csv');
var async = require('async');
var htmlparser = require("htmlparser");
var DomHandler = require("DomHandler");
var DomElementType = require('DomElementType');
var http = require('http'),
fs = require('fs'),
request = require('request');
var urlStockinfo = "http://www.mcxindia.com/SitePages/indexhistory.aspx";
var r = request.get(urlStockinfo);
var resData = "";
var resData1 = "";
var fileNameCsv = "";
var outCsv = "";
if(arrIndexValues[n] !== '' && arrIndexValues[n] != null)
{
fileNameCsv = downloadpath+"mcxindia/MCXIndex"+arrIndexValues[n]+".csv"
outCsv = fs.createWriteStream(fileNameCsv);
}
r.on('response', function(response) {
response.on('data', function(chunk) {
resData += chunk;
});
});
r.on('error',function(){
startProcessForMCXFutureIndexHistory(arrSpotIndexValues, arrIndexValues, startDateForDownloadMCXFutureIndexHistory, endDateForDownloadMCXFutureIndexHistory, outputpath, n, strFileNameIndexHistory);
});
r.on('end', function ()
{
var viewState_value = "";
var eventValidation_value = "";
var mImgBtnGo_X = "";
try{
var parser = new htmlparser.Parser(
{
onopentag: function(name, attribs){
if(name === "input" && attribs["id"] === "__VIEWSTATE"){
viewState_value = attribs["value"];
}
},
ontext:function(text){
},
onclosetag: function(tagname){
}
});
parser.write(resData);
parser.done();
var parser1 = new htmlparser.Parser(
{
onopentag: function(name, attribs){
if(name === "input" && attribs["id"] === "__EVENTVALIDATION"){
eventValidation_value = attribs["value"];
}
},
ontext:function(text){
},
onclosetag: function(tagname){
}
});
parser1.write(resData);
parser1.done();
new htmlparser.FeedHandler(function(error, feed){
console.log('\n Error : '+error);
});
}catch(err)
{
if(err){
document.getElementById("om").innerHTML+="<br/>"+err;
}
}
var r1 = request
(
{
method: 'POST',
uri: urlStockinfo,
headers: {
"User-Agent": "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11",
"Accept-Encoding": "utf-8",
"Accept": "text/plain,application/csv,*/*;q=0.3",
"Cookie": "cookie"
},
form:{
'__VIEWSTATE':viewState_value.trim(),
'__EVENTVALIDATION':eventValidation_value.trim(),
'mDdlOtherIndex':arrIndexValues[n],
'mRbtLstSpotFut_0':'1',
'mTbFromDate':startDateForDownloadMCXFutureIndexHistory,
'mTbToDate':endDateForDownloadMCXFutureIndexHistory,
'mBtnGo.x':'130',
'mBtnGo.y':'40'
}
}
);
r1.on('response', function(response) {
response.on('data', function(chunk) {
resData1 += chunk;
});
});
var viewState_value1 = "";
var eventValidation_value1 = "";
r1.on('error',function(){
startProcessForMCXFutureIndexHistory(arrSpotIndexValues, arrIndexValues, startDateForDownloadMCXFutureIndexHistory, endDateForDownloadMCXFutureIndexHistory, outputpath, n, strFileNameIndexHistory);
});
r1.on('end', function()
{
try{
var parser2 = new htmlparser.Parser(
{
onopentag: function(name, attribs){
if(name === "input" && attribs["id"] === "__VIEWSTATE"){
viewState_value1 = attribs["value"];
}
},
ontext:function(text){
},
onclosetag: function(tagname){
}
});
parser2.write(resData1);
parser2.done();
var parser3 = new htmlparser.Parser(
{
onopentag: function(name, attribs)
{
if(name === "input" && attribs["id"] === "__EVENTVALIDATION"){
eventValidation_value1 = attribs["value"];
}
},
ontext:function(text){
},
onclosetag: function(tagname){
}
});
parser3.write(resData1);
parser3.done();
new htmlparser.FeedHandler(function(error, feed){
console.log('\n Error : '+error);
});
}catch(err)
{
if(err){
document.getElementById("om").innerHTML+="<br/>"+err;
}
}
request
(
{
method: 'POST',
uri: urlStockinfo,
headers: {
"User-Agent": "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11",
"Accept-Encoding": "utf-8",
"Accept": "text/plain,application/csv,*/*;q=0.3",
"Cookie": "cookie"
},
form:{
'__VIEWSTATE':viewState_value1.trim(),
'__EVENTVALIDATION':eventValidation_value1.trim(),
'mDdlOtherIndex':arrIndexValues[n],
'mRbtLstSpotFut_0':'1',
'mTbFromDate':startDateForDownloadMCXFutureIndexHistory,
'mTbToDate':endDateForDownloadMCXFutureIndexHistory,
'__EVENTTARGET':'linkButton'
}
},
function(error, response, body) {
if(response != null)
{
if(response.statusCode != null || response.statusCode != "")
{
if (!error && response.statusCode == 200)
{
downloadmcxcsv(response.statusCode);
}
else
{
downloadmcxcsv(404);
}
}else
{
downloadmcxcsv(404);
}
}else
{
downloadmcxcsv(404);
}
}
);
function downloadmcxcsv(code){
if(code==200){
var r2 = request
(
{
method: 'POST',
uri: urlStockinfo,
headers: {
"User-Agent": "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11",
"Accept-Encoding": "utf-8",
"Accept": "text/plain,application/csv,*/*;q=0.3",
"Cookie": "cookie"
},
form:{
'__VIEWSTATE':viewState_value1.trim(),
'__EVENTVALIDATION':eventValidation_value1.trim(),
'mDdlOtherIndex':arrIndexValues[n],
'mRbtLstSpotFut_0':'1',
'mTbFromDate':startDateForDownloadMCXFutureIndexHistory,
'mTbToDate':endDateForDownloadMCXFutureIndexHistory,
'__EVENTTARGET':'linkButton'
}
}
);
r2.pipe(outCsv);
r2.on('end',function(){
n++;
if(arrIndexValues.length > n)
{
loadprogressbar();
setTimeout(function(){
startProcessForMCXFutureIndexHistory(arrSpotIndexValues, arrIndexValues, startDateForDownloadMCXFutureIndexHistory, endDateForDownloadMCXFutureIndexHistory, outputpath, n, strFileNameIndexHistory);
},1000);
}else
{
Ext.getCmp('pbar3').updateText('NSEL EOD Processing is started . . .');
Ext.getCmp('pbar3').updateProgress(0.05);
setTimeout(function()
{
var om=322;
while(om<327){
process_mcxindex(count,om,baseurl,downloadpath,unzippath,outputpath,logpath);
om++;
}
startProcessForMCXSpotIndexHistory(arrSpotIndexValues, startDateForDownloadMCXFutureIndexHistory, endDateForDownloadMCXFutureIndexHistory, outputpath, 0, strFileNameIndexHistory);
},5000);
}
});
r2.on('error',function(){
startProcessForMCXFutureIndexHistory(arrSpotIndexValues, arrIndexValues, startDateForDownloadMCXFutureIndexHistory, endDateForDownloadMCXFutureIndexHistory, outputpath, n, strFileNameIndexHistory)
});
}
else
{
n++;
if(arrIndexValues.length > n)
{
loadprogressbar();
setTimeout(function(){
startProcessForMCXFutureIndexHistory(arrSpotIndexValues, arrIndexValues, startDateForDownloadMCXFutureIndexHistory, endDateForDownloadMCXFutureIndexHistory, outputpath, n, strFileNameIndexHistory);
},1000);
}else
{
Ext.getCmp('pbar3').updateText('NSEL EOD Processing is started . . .');
Ext.getCmp('pbar3').updateProgress(0.05);
setTimeout(function()
{
var om=322;
while(om<327){
process_mcxindex(count,om,baseurl,downloadpath,unzippath,outputpath,logpath);
om++;
}
startProcessForMCXSpotIndexHistory(arrSpotIndexValues, startDateForDownloadMCXFutureIndexHistory, endDateForDownloadMCXFutureIndexHistory, outputpath, 0, strFileNameIndexHistory);
},5000);
}
}
}
});
});
}catch(err)
{
if(err){
document.getElementById("om").innerHTML+="<br/>"+err;
}
}
}
function startProcessForMCXSpotIndexHistory(arrSpotIndexValues, startDateForDownloadMCXFutureIndexHistory, endDateForDownloadMCXFutureIndexHistory, outputpath, n, strFileNameIndexHistory)
{
try
{
document.getElementById("om").innerHTML+="<br/>MCXSpotIndex"+arrSpotIndexValues[n]+".csv is downloading";
fs = require('fs');
var csv = require('ya-csv');
var async = require('async');
var htmlparser = require("htmlparser");
var DomHandler = require("DomHandler");
var DomElementType = require('DomElementType');
var http = require('http'),
fs = require('fs'),
request = require('request');
var urlStockinfo = "http://www.mcxindia.com/SitePages/indexhistory.aspx";
var r = request.get(urlStockinfo);
var resData = "";
var resData1 = "";
var outCsv;
var fileNameCsv = "";
if(arrSpotIndexValues[n] !== '' && arrSpotIndexValues[n] != null)
{
fileNameCsv = downloadpath+"mcxindia/MCXSpotIndex"+arrSpotIndexValues[n]+".csv"
outCsv = fs.createWriteStream(fileNameCsv);
}
r.on('response', function(response) {
response.on('data', function(chunk) {
resData += chunk;
});
});
r.on('error',function(){
startProcessForMCXSpotIndexHistory(arrSpotIndexValues, startDateForDownloadMCXFutureIndexHistory, endDateForDownloadMCXFutureIndexHistory, outputpath, n, strFileNameIndexHistory);
});
r.on('end', function ()
{
var viewState_value = "";
var eventValidation_value = "";
var mImgBtnGo_X = "";
try{
var parser = new htmlparser.Parser(
{
onopentag: function(name, attribs){
if(name === "input" && attribs["id"] === "__VIEWSTATE"){
viewState_value = attribs["value"];
}
},
ontext:function(text){
},
onclosetag: function(tagname){
}
});
parser.write(resData);
parser.done();
var parser1 = new htmlparser.Parser(
{
onopentag: function(name, attribs){
if(name === "input" && attribs["id"] === "__EVENTVALIDATION"){
eventValidation_value = attribs["value"];
}
},
ontext:function(text){
},
onclosetag: function(tagname){
}
});
parser1.write(resData);
parser1.done();
new htmlparser.FeedHandler(function(error, feed){
console.log('\n Error : '+error);
});
}catch(err)
{
if(err){
document.getElementById("om").innerHTML+="<br/>"+err;
}
}
var r1 = request
(
{
method: 'POST',
uri: urlStockinfo,
headers:
{
"User-Agent": "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11",
"Accept-Encoding": "utf-8",
"Accept": "text/plain,application/csv,*/*;q=0.3",
"Cookie": "cookie"
},
form:
{
'__VIEWSTATE':viewState_value.trim(),
'__EVENTVALIDATION':eventValidation_value.trim(),
'mRbtLstSpotFut':'0'
}
}
);
r1.on('response', function(response)
{
response.on('data', function(chunk) {
resData1 += chunk;
});
});
var viewState_value1 = "";
var eventValidation_value1 = "";
r1.on('error',function(){
startProcessForMCXSpotIndexHistory(arrSpotIndexValues, startDateForDownloadMCXFutureIndexHistory, endDateForDownloadMCXFutureIndexHistory, outputpath, n, strFileNameIndexHistory);
});
r1.on('end', function()
{
try
{
var parser2 = new htmlparser.Parser(
{
onopentag: function(name, attribs){
if(name === "input" && attribs["id"] === "__VIEWSTATE"){
viewState_value1 = attribs["value"];
}
},
ontext:function(text){
},
onclosetag: function(tagname){
}
});
parser2.write(resData1);
parser2.done();
var parser3 = new htmlparser.Parser(
{
onopentag: function(name, attribs)
{
if(name === "input" && attribs["id"] === "__EVENTVALIDATION"){
eventValidation_value1 = attribs["value"];
}
},
ontext:function(text){
},
onclosetag: function(tagname){
}
});
parser3.write(resData1);
parser3.done();
new htmlparser.FeedHandler(function(error, feed){
console.log('\n Error : '+error);
});
}catch(err)
{
if(err){
document.getElementById("om").innerHTML+="<br/>"+err;
}
}
var resData4 = "";
var r4 = request
(
{
method: 'POST',
uri: urlStockinfo,
headers:
{
"User-Agent": "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11",
"Accept-Encoding": "utf-8",
"Accept": "text/plain,application/csv,*/*;q=0.3",
"Cookie": "cookie"
},
form:
{
'__VIEWSTATE':viewState_value1.trim(),
'__EVENTVALIDATION':eventValidation_value1.trim(),
'mDdlOtherIndex':arrSpotIndexValues[n],
'mTbFromDate':startDateForDownloadMCXFutureIndexHistory,
'mTbToDate':endDateForDownloadMCXFutureIndexHistory,
'mBtnGo.x':'130',
'mBtnGo.y':'40'
}
}
);
r4.on('response', function(response) {
response.on('data', function(chunk) {
resData4 += chunk;
});
});
var viewState_value4 = "";
var eventValidation_value4 = "";
r4.on('error',function(){
startProcessForMCXSpotIndexHistory(arrSpotIndexValues, startDateForDownloadMCXFutureIndexHistory, endDateForDownloadMCXFutureIndexHistory, outputpath, n, strFileNameIndexHistory);
});
r4.on('end', function()
{
try{
var parser4 = new htmlparser.Parser(
{
onopentag: function(name, attribs){
if(name === "input" && attribs["id"] === "__VIEWSTATE"){
viewState_value4 = attribs["value"];
}
},
ontext:function(text){
},
onclosetag: function(tagname){
}
});
parser4.write(resData4);
parser4.done();
var parser5 = new htmlparser.Parser(
{
onopentag: function(name, attribs)
{
if(name === "input" && attribs["id"] === "__EVENTVALIDATION"){
eventValidation_value4 = attribs["value"];
}
},
ontext:function(text){
},
onclosetag: function(tagname){
}
});
parser5.write(resData4);
parser5.done();
new htmlparser.FeedHandler(function(error, feed){
console.log('\n Error : '+error);
});
}catch(err)
{
if(err){
document.getElementById("om").innerHTML+="<br/>"+err;
}
}
request
(
{
method: 'POST',
uri: urlStockinfo,
headers:
{
"User-Agent": "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11",
"Accept-Encoding": "utf-8",
"Accept": "text/plain,application/csv,*/*;q=0.3",
"Cookie": "cookie"
},
form:
{
'__VIEWSTATE':viewState_value4.trim(),
'__EVENTVALIDATION':eventValidation_value4.trim(),
'mDdlOtherIndex':arrSpotIndexValues[n],
'mTbFromDate':startDateForDownloadMCXFutureIndexHistory,
'mTbToDate':endDateForDownloadMCXFutureIndexHistory,
'__EVENTTARGET':'linkButton'
}
},
function(error, response, body) {
if(response != null)
{
if(response.statusCode != null || response.statusCode != "")
{
if (!error && response.statusCode == 200)
{
downloadmcxcsv(response.statusCode);
}
else
{
downloadmcxcsv(404);
}
}else
{
downloadmcxcsv(404);
}
}else
{
downloadmcxcsv(404);
}
}
);
function downloadmcxcsv(code){
if(code==200){
var r2 = request
(
{
method: 'POST',
uri: urlStockinfo,
headers:
{
"User-Agent": "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11",
"Accept-Encoding": "utf-8",
"Accept": "text/plain,application/csv,*/*;q=0.3",
"Cookie": "cookie"
},
form:
{
'__VIEWSTATE':viewState_value4.trim(),
'__EVENTVALIDATION':eventValidation_value4.trim(),
'mDdlOtherIndex':arrSpotIndexValues[n],
'mTbFromDate':startDateForDownloadMCXFutureIndexHistory,
'mTbToDate':endDateForDownloadMCXFutureIndexHistory,
'__EVENTTARGET':'linkButton'
}
}
);
r2.pipe(outCsv);
r2.on('end',function(){
document.getElementById("om").innerHTML+="<br/>MCXSpotIndex"+arrSpotIndexValues[n]+".csv is downloaded"
n++;
if(arrIndexValues.length > n)
{
loadprogressbar();
setTimeout(function(){
startProcessForMCXSpotIndexHistory(arrSpotIndexValues, startDateForDownloadMCXFutureIndexHistory, endDateForDownloadMCXFutureIndexHistory, outputpath, n, strFileNameIndexHistory);
},1000);
}else
{
Ext.getCmp('pbar3').updateProgress(0.005);
setTimeout(function(){
var om=327;
while(om<331)
{
process_mcxspotindex(count,om,baseurl,downloadpath,unzippath,outputpath,logpath);
om++;
}
sn++;
callfun(count,baseurl,downloadpath,unzippath,outputpath,logpath,fromd,tod,sn);
},5000);
}
});
r2.on('error',function(){
startProcessForMCXSpotIndexHistory(arrSpotIndexValues, startDateForDownloadMCXFutureIndexHistory, endDateForDownloadMCXFutureIndexHistory, outputpath, n, strFileNameIndexHistory);
});
}
else
{
document.getElementById("om").innerHTML+="<br/>MCXSpotIndex"+arrSpotIndexValues[n]+".csv is not downloaded"
n++;
if(arrIndexValues.length > n)
{
loadprogressbar();
setTimeout(function(){
startProcessForMCXSpotIndexHistory(arrSpotIndexValues, startDateForDownloadMCXFutureIndexHistory, endDateForDownloadMCXFutureIndexHistory, outputpath, n, strFileNameIndexHistory);
},1000);
}else
{
Ext.getCmp('pbar3').updateProgress(0.005);
setTimeout(function(){
var om=327;
while(om<331)
{
process_mcxspotindex(count,om,baseurl,downloadpath,unzippath,outputpath,logpath);
om++;
}
sn++;
callfun(count,baseurl,downloadpath,unzippath,outputpath,logpath,fromd,tod,sn);
},5000);
}
}
}
});
});
});
}catch(err)
{
console.error(err.stack);
document.getElementById("om").innerHTML+="<br/>MCXSpotIndex"+arrSpotIndexValues[n]+".csv is not downloaded"
n++;
if(arrIndexValues.length > n)
{
loadprogressbar();
setTimeout(function(){
startProcessForMCXSpotIndexHistory(arrSpotIndexValues, startDateForDownloadMCXFutureIndexHistory, endDateForDownloadMCXFutureIndexHistory, outputpath, n, strFileNameIndexHistory);
},1000);
}else
{
Ext.getCmp('pbar3').updateProgress(0.005);
setTimeout(function(){
var om=327;
while(om<331)
{
process_mcxspotindex(count,om,baseurl,downloadpath,unzippath,outputpath,logpath);
om++;
}
sn++;
callfun(count,baseurl,downloadpath,unzippath,outputpath,logpath,fromd,tod,sn);
},5000);
}
}
}
function getMonth(mon){
var month='';
switch(mon.toUpperCase())
{
case 'JAN':
month='01';
break;
case 'FEB':
month='02';
break;
case 'MAR':
month='03';
break;
case 'APR':
month='04';
break;
case 'MAY':
month='05';
break;
case 'JUN':
month='06';
break;
case 'JUL':
month='07';
break;
case 'AUG':
month='08';
break;
case 'SEP':
month='09';
break;
case 'OCT':
month='10';
break;
case 'NOV':
month='11';
break;
case 'DEC':
month='12';
break;
}
return month;
}
}catch(err)
{
console.log(err);
}
}