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.

331 lines (288 loc) 12.8 kB
/***************************** * *Author:JAYANT PATIL *COMPANY NAME XNet Inc,Pune. *last modified date:08-jan-2013 * * * *Description: *This will process BSE Equity data * *variables : *count --->contains array of date in which we take one date process files regarding to that *n --->it is a counter variable *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_yahoodata(count,baseurl,downloadpath,unzippath,outputpath,logpath,fromd,tod,sn) { try { try{ var fs = require('fs'); var csv = require('ya-csv'); var async = require('async'); async.parallel({ data1 : function(callback){ if (fs.existsSync('yahoo.csv')) { fs.readFile('yahoo.csv','utf-8', function(err, data){ 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('./', function(err, files){ callback(err,'0'); }); } } }, function(err, result){ if(err) throw err; if (fs.existsSync('yahoo.csv')) { var arrRow = new Array(); arrRow = result['data1'].split('\n'); if(arrRow.length>0) { var arrFileData = new Array(); // arrRow.lenght-3 is for last 3 lines of no use in file for(var i=0 ; i<arrRow.length-1;i++) { var tempArr = arrRow[i].split(',')[0]; arrFileData.push(tempArr); } senddata(arrFileData); } else { document.getElementById("om").innerHTML+="<br/><font color=lightcoral>Please add yahoo symbols to download yahoo data</font>"; sn++; callfun(count,baseurl,downloadpath,unzippath,outputpath,logpath,fromd,tod,sn); } } else { document.getElementById("om").innerHTML+="<br/><font color=lightcoral>Please add yahoo symbols to download yahoo data</font>"; sn++; callfun(count,baseurl,downloadpath,unzippath,outputpath,logpath,fromd,tod,sn); } }); }catch(err){ console.error(err); } function senddata(a){ //document.getElementById("om").innerHTML+="<br/>Array<br/>"+a; var d=a.toString().replace(/,/g,'+'); //processing all data here var http = require('http'),fs = require('fs'), request = require('request'); var url_seclist='http://download.finance.yahoo.com/d/quotes.csv?s='+d+'&f=snl1ee7e8e9r5b4j4p5s6s7r1qdt8j1f6&e=.csv'; request( { method: 'GET', uri: url_seclist, 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": "", "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 (!error && response.statusCode == 200) { downloadyahoocsv(response.statusCode); } else { downloadyahoocsv(response.statusCode); } } ); function downloadyahoocsv(statuscode) { if(statuscode==200){ //if (fs.existsSync(unzippath+'SCBSEALL'+d+m+'.txt')) { var secout = fs.createWriteStream(downloadpath+'Yahoo_Fundamental.csv'); // For saving NSE Equity Sec list //console.log(secout); //} var req=request( { method: 'GET', uri: url_seclist, 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": "", "Accept-Encoding": "gzip,deflate,sdch", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,**;q=0.8", "Cookie": "cookie" } }); req.pipe(secout); loadprogressbar(); req.on('end',function(){ processyahoofun(count,0,baseurl,downloadpath,unzippath,outputpath,logpath,fromd,tod,sn); /* document.getElementById("om").innerHTML+="<br/>Yahoo_Fundamental.csv is processed"; Ext.getCmp('pbar3').updateText("Yahoo_Fundamental.csv is processed.."); addlog(logpath, 'Yahoo_Fundamental.csv is downloaded'); /************\/ visit('yahoofunda.html'); /***************\/ /*sn++; callfun(count,baseurl,downloadpath,unzippath,outputpath,logpath,fromd,tod,sn); */}); } else { document.getElementById("om").innerHTML+="<br/><font color=red>Yahoo_Fundamental.csv is not on server</font>"; addlog(logpath, 'Yahoo_Fundamental.csv is not on server'); } } } } catch(err) { if(err){document.getElementById("om").innerHTML+="<br/>"+err;} } function processyahoofun(count,n,baseurl,downloadpath,unzippath,outputpath,logpath,fromd,tod,sn) { try{ outputpath=outputpath; var mon=count[n].split('-')[0]; var m=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'); //var path = require('./node_modules/path'); //var writeFileStream = fs.createWriteStream('./tempData/output.txt',{flag:'a',encoding:'utf-8'}); async.parallel({ data1 : function(callback){ if (fs.existsSync(downloadpath+'Yahoo_Fundamental.csv')) { Ext.getCmp('pbar3').updateText('Processing etf'+d+m+y+'.csv'); fs.readFile(downloadpath+'Yahoo_Fundamental.csv','utf-8', function(err, data){ if(err) { document.getElementById("om").innerHTML+="<br/>An error occured while reading "+unzippath+"etf"+d+m+y+".csv"; } // console.log('\n Reading etf191212.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 reading "+unzippath+"etf"+d+m+y+".csv"; } callback(err,'0'); }); } } }, function(err, result){ if(err) { document.getElementById("om").innerHTML+="<br/>An error occured while processing "+unzippath+"etf"+d+m+y+".csv"; } //console.log(unzippath+'etf'+d+m+y+'.csv'); if (fs.existsSync(downloadpath+'Yahoo_Fundamental.csv')) { Ext.getCmp('pbar3').updateText('Processing etf'+d+m+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++) { //arrRow[i].replace("\"", "").trim(); arrRow[i]=arrRow[i].toString().replace(/"/g, '').trim(); /*if(arrFileData[i]== "\"N/A\"" || arrFileData[i]== "" || arrFileData[i]== null ||arrFileData[i]== "N/A" || arrFileData[i]== "NaN" || arrFileData[i] == "undefined" || typeof arrFileData[i]== "undefined") { arrRow[i]=0; }*/ arrRow[i]=arrRow[i].toString().replace(/\//g, '').trim(); arrRow[i]=arrRow[i].toString().replace(/NA/g, '0').trim(); //arrRow[i]=arrRow[i].substring(0, arrRow[i].length -2); var tempArr = arrRow[i].split(','); arrFileData.push(tempArr); } var filename = outputpath+'Yahoo_Fundamental.csv'; var header='TICKER,NAME,DATE,OPEN,HIGH,LOW,CLOSE,VOLUME,OPENINT'; var date=yy+m+d; if(!fs.existsSync(filename)){ //processing actual data for(var i=0 ; i<arrFileData.length-1;i++) { fs.appendFileSync(filename, arrFileData[i]+'\n','UTF-8', function (err) { if(err) { document.getElementById("om").innerHTML+="<br/>An error occured while processing "+unzippath+"etf"+d+m+y+".csv"; } //console.log('etf processsed!'); }); } } } }); //Ext.getCmp('pbar3').updateText('Processing etf'+d+m+y+'.csv completed'); document.getElementById("om").innerHTML+='<br/>etf'+d+m+y+'.csv is processed'; addlog(logpath, 'etf'+d+m+y+'.csv is processed'); n++; if(count.length>n) { loadprogressbar(); setTimeout(function (){ processyahoofun(count,n,baseurl,downloadpath,unzippath,outputpath,logpath,fromd,tod,sn) }, 1000); //setTimeout(function (){process_nse(count,n,baseurl,downloadpath,unzippath,outputpath)}, 5000); document.getElementById("om").innerHTML+='..'; } else{ loadprogressbar(); sn++; callfun(count,baseurl,downloadpath,unzippath,outputpath,logpath,fromd,tod,sn); } } catch(err) { document.getElementById("om").innerHTML+="<br/>An error occured while processing "+unzippath+"etf"+d+m+y+".csv"; n++; if(count.length>n) { loadprogressbar(); setTimeout(function (){ processyahoofun(count,n,baseurl,downloadpath,unzippath,outputpath,logpath,fromd,tod,sn) }, 1000); //setTimeout(function (){process_nse(count,n,baseurl,downloadpath,unzippath,outputpath)}, 5000); document.getElementById("om").innerHTML+='..'; } else{ loadprogressbar(); sn++; callfun(count,baseurl,downloadpath,unzippath,outputpath,logpath,fromd,tod,sn); } } } }