UNPKG

shubhadownloader

Version:

There is large amount of information available in market place. The markets are always in sync. In today's world investors find it very difficult to make effective use of information available to them. Shubha Downloader is great tool which resolves this problem and helps investor to increase his productivity and stay focused on decision making. Shubha Downloader enable end user to download market data from available sources and organize it. Shubha Downloader is Open source & FREE utility for end users. Shubha Downloader have main features as follows End of the day market data from web to your favorite charting application . Fundamental market data from web to your favorite charting application. Market reports from web to your favorite charting application.

260 lines (214 loc) 10.9 kB
/***************************** * *Author:PRASHANT SHILIMKAR *COMPANY NAME XNet Inc,Pune. *last modified date:10-jan-2013 * * * *Description: * * *variables : *baseurl-->it contians all url for nse equity *downloadpath---> it contain download path of file for processing *unzippath ----> it contains unzip folder path *outputpah ----> it containds output older path * * *copyright 2013 ******************************/ /******************************** <Shubha Downloader, It downloads end of day pricing data from publicly available sites and converts it different formats....> Copyright (C) 2013 Shubhalabha.in This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/> ***********************************/ function process_bse_blockdeal(baseurl,downloadpath,unzippath,outputpath,fromd,tod,logpath,sn,count) { try { Ext.getCmp('pbar3').updateText('BSE Block Deal 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;//document.getElementById("datefield-1031-inputEl").value; var dateto=tod;//document.getElementById("datefield-1033-inputEl").value; 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); var dateFormateForBulk = arrendCurrentDate[2]+strMonth.substring(0, 1).toUpperCase() + strMonth.substring(1).toLowerCase()+arrendCurrentDate[3]; downloadAndProcessBSEBlock(dateFormateForBulk, tempPath, outputpath); function downloadAndProcessBSEBlock(dateFormateForBulk, tempPath, outputpath) { //http://www.bseindia.com/stockinfo/BulkBlockFiles/Block_26Dec2012.csv var urlStockinfo = "http://www.bseindia.com/stockinfo/BulkBlockFiles/Block_"+dateFormateForBulk+".csv"; var tempFilePath = tempPath+"temp_block_"+dateFormateForBulk+".csv"; var fname = "temp_block_"+dateFormateForBulk+".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.bseindia.com/stockinfo/BulknBlockDeals.aspx", "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); downloadBlockData(200, urlStockinfo, tempFilePath, fname, dateFormateForBulk, outputpath); } else { downloadBlockData(404, urlStockinfo, tempFilePath, fname, dateFormateForBulk, outputpath); } }else { downloadBlockData(404, urlStockinfo, tempFilePath, fname, dateFormateForBulk, outputpath); } }else { downloadBlockData(404, urlStockinfo, tempFilePath, fname, dateFormateForBulk, outputpath); } } ); } function downloadBlockData(statuscode, urlStockinfo, tempFilePath, fname, dateFormateForBulk, outputpath_block) { if(statuscode==200) { Ext.getCmp('pbar3').updateText('Downloading '+fname); var out = fs.createWriteStream(tempFilePath); // For saving NSE Equity bhavcopy 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.bseindia.com/stockinfo/BulknBlockDeals.aspx", "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); //request pipeout 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/> An error occured while processing bseblockdeals.csv";} callback(err, data); }); }else { // Here readdir's functionaliity has no use. It is written for only to send // '0' data in its callback function because we cannot call "callback(err, data);" // function out side a callback function fs.readdir(downloadpath, function(err, files){ if(err){document.getElementById("om").innerHTML+="<br/> An error occured while processing bseblockdeals.csv";} 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'); //console.log('\nop '+outputpath_block); if(fs.existsSync(outputpath_block+'bseblockdeals.csv')) { // file exist - dont append header for(var i=1 ; i<arrFileData.length-1;i++) { fs.appendFileSync(outputpath_block+'bseblockdeals.csv', arrFileData[i]+'\n','utf-8', function (err) { if(err){document.getElementById("om").innerHTML+="<br/> An error occured while processing bseblockdeals.csv";} }); } } else { // file not exist - append header for(var i=0 ; i<arrFileData.length-1;i++) { fs.appendFileSync(outputpath_block+'bseblockdeals.csv', arrFileData[i]+'\n','utf-8', function (err) { if(err){document.getElementById("om").innerHTML+="<br/> An error occured while processing bseblockdeals.csv";} }); } Ext.getCmp('pbar3').updateText('Processing '+fname+' completed'); } } //document.getElementById("om").innerHTML+='<br/><font color=green> Finished </font>'; }); // parallel Ext.getCmp('pbar3').updateText(''+fname+' is downloaded'); document.getElementById("om").innerHTML+='<br>'+fname+' is downloaded...'; loadprogressbar(); setTimeout(function(){process_nse_bc(count,count.length-1,baseurl,downloadpath,unzippath,outputpath,logpath,fromd,tod,sn);},1000); }); //on end } else { Ext.getCmp('pbar3').updateText('File '+fname+' is not present on server'); document.getElementById("om").innerHTML+='<br/><font color=red>'+fname+' is not present on server</font>'; loadprogressbar(); setTimeout(function(){process_nse_bc(count,count.length-1,baseurl,downloadpath,unzippath,outputpath,logpath,fromd,tod,sn);},1000); } } }catch(err) { Ext.getCmp('pbar3').updateText('File '+fname+' is not present on server'); document.getElementById("om").innerHTML+='<br/><font color=red>'+fname+' is not present on server</font>'; loadprogressbar(); setTimeout(function(){process_nse_bc(count,count.length-1,baseurl,downloadpath,unzippath,outputpath,logpath,fromd,tod,sn);},1000); } }