function nse_equity_vol(baseurl,downloadpath,unzippath,outputpath,fromd,tod,logpath,sn,count)
{
try{
Ext.getCmp('pbar3').updateText('NSE Equity Volume Processing is started . . .');
Ext.getCmp('pbar3').updateProgress(0.05);
var url = require('url');
var async = require('async');
var http = require('http'),fs = require('fs'),AdmZip = require('adm-zip'),request = require('request');
var datefrom=fromd;
var dateto=tod;
var fromdate=datefrom.split('/');
var todate=dateto.split('/');
var beginDate = new Date(fromdate[0]+','+fromdate[1]+','+fromdate[2]);
var endDate1 = new Date(todate[0]+','+todate[1]+','+todate[2]);
var arrCurrentDate = beginDate.toDateString().split(" ");
var arrendCurrentDate = endDate1.toDateString().split(" ");
var strMonthUpper = arrCurrentDate[1].toUpperCase();
var intMonth = beginDate.getMonth()+1;
var intendMonth = endDate1.getMonth()+1;
var stDateFormate = intMonth+"/"+arrCurrentDate[2]+"/"+arrCurrentDate[3];
var endDateFormate = intendMonth+"/"+arrendCurrentDate[2]+"/"+arrendCurrentDate[3];
var tempPath = downloadpath+'temp/';
var strMonth = getmonth(intendMonth);
if(intendMonth < 10)
intendMonth = '0'+intendMonth;
var strStart_date = arrCurrentDate[2]+''+intMonth+''+arrCurrentDate[3];
var strEnd_date = arrendCurrentDate[2]+''+intendMonth+''+arrendCurrentDate[3];
downloadAndProcessNSEEquityVol(strStart_date, strEnd_date, tempPath, outputpath);
function downloadAndProcessNSEEquityVol(strStart_date, strEnd_date, tempPath, outputpath)
{
var urlStockinfo = "http://www.nseindia.com/content/nsccl/fao_participant_vol_"+strEnd_date+".csv";
var tempFilePath = tempPath+"NSEtemp_vol_"+strEnd_date+".csv";
var fname = "NSEtemp_vol_"+strEnd_date+".csv";
request
(
{
method: 'GET',
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",
"Referer": "http://www.nseindia.com/products/content/all_daily_reports.htm",
"Accept-Encoding": "gzip,deflate,sdch",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"Cookie": "cookie"
}
},
function(error, response, body)
{
if(response != null)
{
if(response.statusCode != null || response.statusCode != "")
{
if (!error && response.statusCode == 200)
{
Ext.getCmp('pbar3').updateText('Downloading '+fname);
downloadNSEEquityVol(200, urlStockinfo, tempFilePath, fname, outputpath);
}
else
{
downloadNSEEquityVol(200, urlStockinfo, tempFilePath, fname, outputpath);
}
}else
{
downloadNSEEquityVol(200, urlStockinfo, tempFilePath, fname, outputpath);
}
}else
{
downloadNSEEquityVol(200, urlStockinfo, tempFilePath, fname, outputpath);
}
}
);
}
function downloadNSEEquityVol(statuscode, urlStockinfo, tempFilePath, fname, outputpath_block)
{
if(statuscode==200)
{
Ext.getCmp('pbar3').updateText('Downloading '+fname);
var out = fs.createWriteStream(tempFilePath);
var req = request(
{
method: 'GET',
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",
"Referer": "http://www.nseindia.com/products/content/all_daily_reports.htm",
"Accept-Encoding": "gzip,deflate,sdch",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"Cookie": "cookie"
}
});
req.on('error',function()
{
Ext.getCmp('pbar3').updateText('Error occurred while downloading '+fname+'');
document.getElementById("om").innerHTML+='<br/>Error occured in downloading '+fname;
});
req.pipe(out);
req.on('end', function()
{
var async = require('async');
async.parallel(
{
data1 : function(callback){
if (fs.existsSync(tempFilePath)) {
fs.readFile(tempFilePath,'utf-8', function(err, data){
if(err){document.getElementById("om").innerHTML+="<br/>"+err;}
callback(err, data);
});
}else
{
fs.readdir(downloadpath, function(err, files){
if(err){document.getElementById("om").innerHTML+="<br/>"+err;}
callback(err,'0');
});
}
}
}, function(err, result)
{
if(err){document.getElementById("om").innerHTML+="<br/>"+err;}
if (fs.existsSync(tempFilePath))
{
Ext.getCmp('pbar3').updateText('Processing '+fname+'');
var arrRow = new Array();
arrRow = result['data1'].split('\n');
var arrFileData = new Array();
for(var i=0 ; i<arrRow.length;i++)
{
var tempArr = arrRow[i].split(',');
arrFileData.push(tempArr);
}
outputpath_block=outputpath_block.replace(/std_csv/g,'reports');
for(var i=0 ; i<arrFileData.length-1;i++)
{
fs.appendFileSync(outputpath_block+'NSE_fao_participant_vol_reports.csv', arrFileData[i]+'\n','utf-8', function (err) {
if(err){document.getElementById("om").innerHTML+="<br/>"+err;}
});
}
Ext.getCmp('pbar3').updateText('Processing '+fname+' completed');
}
});
Ext.getCmp('pbar3').updateText(''+fname+' is downloaded');
document.getElementById("om").innerHTML+='<br>'+fname+' is downloaded...';
loadprogressbar();
setTimeout(function(){nse_equity_openint(baseurl,downloadpath,unzippath,outputpath,fromd,tod,logpath,sn,count);},1000);
});
}
else
{
Ext.getCmp('pbar3').updateText('File '+fname+' is not present on server');
Ext.getCmp('pbar3').updateProgress(1.0);
document.getElementById("om").innerHTML+='<br/><font color=red>'+fname+' is not present on server</font>';
loadprogressbar();
setTimeout(function(){nse_equity_openint(baseurl,downloadpath,unzippath,outputpath,fromd,tod,logpath,sn,count);},1000);
}
}
}catch(err){console.log(err);Ext.getCmp('pbar3').updateText('File '+fname+' is not present on server');
Ext.getCmp('pbar3').updateProgress(1.0);
document.getElementById("om").innerHTML+='<br/><font color=red>'+fname+' is not present on server</font>';
loadprogressbar();
setTimeout(function(){nse_equity_openint(baseurl,downloadpath,unzippath,outputpath,fromd,tod,logpath,sn,count);},1000);
}
}