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.

212 lines (183 loc) 9.23 kB
/******************************** <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_nsema(count,n,baseurl,downloadpath,unzippath,outputpath,logpath,fromd,tod,sn) { try { var mon=count[n].split('-')[0]; var m1=count[n].split('-')[1]; var d=count[n].split('-')[2]; var yy=count[n].split('-')[3]; var y=yy.substr(2,2); var fs = require('fs'); var csv = require('ya-csv'); var async = require('async'); try{ async.parallel({ data1 : function(callback){ if (fs.existsSync(downloadpath+'MA'+d+m1+y+'.csv')) { Ext.getCmp('pbar3').updateText('Processing MA'+d+m1+y+'.csv'); Ext.getCmp('pbar3').updateProgress(0.05); fs.readFile(downloadpath+'MA'+d+m1+y+'.csv','utf-8', function(err, data){ if(err){document.getElementById("om").innerHTML+="<br/>"+err;} //console.log('\n Reading MA.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/>"+err;} callback(err,'0'); }); } } }, function(err, result){ if(err){document.getElementById("om").innerHTML+="<br/>"+err;} if (fs.existsSync(downloadpath+'MA'+d+m1+y+'.csv')) { Ext.getCmp('pbar3').updateText('Processing MA'+d+m1+y+'.csv'); var arrRow = new Array(); arrRow = result['data1'].split('\n'); var arrFileData = new Array(); // arrRow.lenght-3 is for last 3 lines of no use in file for(var i=0 ; i<arrRow.length;i++) { var tempArr = arrRow[i].split(','); arrFileData.push(tempArr); } var outputpath1=outputpath.replace(/std_csv/g,'reports'); var filename = outputpath1+'nsemarket_activity.csv'; //check for the avaliability of file (existence).... var date = yy+m1+d; if (fs.existsSync(filename)) { //processing actual data of file ... var count=0; fs.appendFileSync(filename, date+'\n\n','UTF-8', function (err) { if (err) {console.log(err);} }); for(i=1; i<arrFileData.length;i++) { if(arrFileData[i][1]=="ADVANCES") { fs.appendFileSync(outputpath+'NSE_Advance_D_nsead.csv', 'NSE_'+arrFileData[i][1]+','+'NSE_'+arrFileData[i][1]+','+date+','+arrFileData[i][2]+','+arrFileData[i][2]+','+arrFileData[i][2]+','+arrFileData[i][2]+',0,0'+'\n','UTF-8', function (err) { if (err) {console.log(err);} }); } if(arrFileData[i][1]=="DECLINES") { fs.appendFileSync(outputpath+'NSE_Advance_D_nsead.csv', 'NSE_'+arrFileData[i][1]+','+'NSE_'+arrFileData[i][1]+','+date+','+arrFileData[i][2]+','+arrFileData[i][2]+','+arrFileData[i][2]+','+arrFileData[i][2]+',0,0'+'\n','UTF-8', function (err) { if (err) {console.log(err);} }); } if(arrFileData[i][1]=="UNCHANGED") { fs.appendFileSync(outputpath+'NSE_Advance_D_nsead.csv', 'NSE_'+arrFileData[i][1]+','+'NSE_'+arrFileData[i][1]+','+date+','+arrFileData[i][2]+','+arrFileData[i][2]+','+arrFileData[i][2]+','+arrFileData[i][2]+',0,0'+'\n','UTF-8', function (err) { if (err) {console.log(err);} }); } fs.appendFileSync(filename, arrFileData[i]+'\n','UTF-8', function (err) { if (err) {console.log(err);} }); } Ext.getCmp('pbar3').updateText('Processing HL'+d+m1+y+'.csv completed'); } else { var header='TICKER,NAME,DATE,OPEN,HIGH,LOW,CLOSE,VOLUME,OPENINT'; fs.writeFile(outputpath+'NSE_Advance_D_nsead.csv', header+'\n', function (err) { if (err) console.log(err+'\n'); }); //appending headers to file here fs.writeFile(filename, date+'\n\n', function (err) { if (err) console.log(err+'\n');; //processing actual data of file ... for(i=1; i<arrFileData.length;i++) { if(arrFileData[i][1]=="ADVANCES") { fs.appendFileSync(outputpath+'NSE_Advance_D_nsead.csv', 'NSE_'+arrFileData[i][1]+','+'NSE_'+arrFileData[i][1]+','+date+','+arrFileData[i][2]+','+arrFileData[i][2]+','+arrFileData[i][2]+','+arrFileData[i][2]+',0,0'+'\n','UTF-8', function (err) { if (err) {console.log(err);} }); } if(arrFileData[i][1]=="DECLINES") { fs.appendFileSync(outputpath+'NSE_Advance_D_nsead.csv', 'NSE_'+arrFileData[i][1]+','+'NSE_'+arrFileData[i][1]+','+date+','+arrFileData[i][2]+','+arrFileData[i][2]+','+arrFileData[i][2]+','+arrFileData[i][2]+',0,0'+'\n','UTF-8', function (err) { if (err) {console.log(err);} }); } if(arrFileData[i][1]=="UNCHANGED") { fs.appendFileSync(outputpath+'NSE_Advance_D_nsead.csv', 'NSE_'+arrFileData[i][1]+','+'NSE_'+arrFileData[i][1]+','+date+','+arrFileData[i][2]+','+arrFileData[i][2]+','+arrFileData[i][2]+','+arrFileData[i][2]+',0,0'+'\n','UTF-8', function (err) { if (err) {console.log(err);} }); } fs.appendFileSync(filename, arrFileData[i]+'\n','UTF-8', function (err) { if (err) {console.log(err);} }); } }); Ext.getCmp('pbar3').updateText('Processing HL'+d+m1+y+'.csv completed'); } } }); }catch(err){ if(err){document.getElementById("om").innerHTML+="<br/>"+err;} } document.getElementById("om").innerHTML+="<br/>MA"+d+m1+y+".csv is processed.."; addlog(logpath, 'MA'+d+m1+y+'.csv is processed..'); n++; if(count.length>n) { loadprogressbar(); setTimeout(function (){process_nsema(count,n,baseurl,downloadpath,unzippath,outputpath,logpath,fromd,tod,sn)}, 1000); document.getElementById("om").innerHTML+='..';} else{ Ext.getCmp('pbar3').updateProgress(0); /************/ visit('reports.html'); /***************/ process_nse_bulk(baseurl,downloadpath,unzippath,outputpath,fromd,tod,logpath,sn,count); } function monthDiff(d1, d2) { var months; months = (d2.getFullYear() - d1.getFullYear()) * 12; months -= d1.getMonth() + 1; months += d2.getMonth(); return months+1; } }catch(err) { console.log(err); n++; if(count.length>n) { loadprogressbar(); setTimeout(function (){process_nsema(count,n,baseurl,downloadpath,unzippath,outputpath,logpath,fromd,tod,sn)}, 1000); document.getElementById("om").innerHTML+='..';} else{ Ext.getCmp('pbar3').updateProgress(0); /************/ visit('reports.html'); /***************/ process_nse_bulk(baseurl,downloadpath,unzippath,outputpath,fromd,tod,logpath,sn,count); } } // return numeric month for symbolic month arg }