function process_googleieod(count,baseurl,downloadpath,unzippath,outputpath,logpath,fromd,tod,sn,yahoo_min,days)
{
var fs = require('fs');
var csv = require('ya-csv');
var async = require('async');
try{
async.parallel({
data1 : function(callback){
if (fs.existsSync('google.csv')) {
fs.readFile('google.csv','utf-8', function(err, data){
callback(err, data);
});
}else
{
fs.readdir('./', function(err, files){
callback(err,'0');
});
}
}
}, function(err, result){
if(err) throw err;
if (fs.existsSync('google.csv')) {
var arrRow = new Array();
arrRow = result['data1'].split('\n');
if(arrRow.length>0)
{
var arrFileData = new Array();
for(var i=0 ; i<arrRow.length-1;i++)
{
arrFileData.push(arrRow[i].trim());
}
downloadAndProcessGoogleIEOD(count,baseurl,downloadpath,unzippath,outputpath,logpath,fromd,tod,sn,arrFileData, yahoo_min, 0,days);
}
else
{
sn++;
callfun(count,baseurl,downloadpath,unzippath,outputpath,logpath,fromd,tod,sn);
}
}
});
}catch(err){
console.error(err);
}
}
function downloadAndProcessGoogleIEOD(count,baseurl,downloadpath,unzippath,outputpath,logpath,fromd,tod,sn,arrYahooSymbols,yahoo_min,n,days)
{
var urlStockinfo = "";
if(yahoo_min == "1")
urlStockinfo = 'http://www.google.com/finance/getprices?q='+arrYahooSymbols[n].split(":")[1]+'&x='+arrYahooSymbols[n].split(":")[0]+'&i=60&p='+days+'d&f=d,o,h,l,c,v&df=cpct&auto=1&ts=126670129' ;
if(yahoo_min == "5")
urlStockinfo = 'http://www.google.com/finance/getprices?q='+arrYahooSymbols[n].split(":")[1]+'&x='+arrYahooSymbols[n].split(":")[0]+'&i=300&p='+days+'d&f=d,o,h,l,c,v&df=cpct&auto=1&ts=126670129' ;
var http = require('http'),
fs = require('fs'),
request = require('request');
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": "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)
{
downloadgoogleieod(count,baseurl,downloadpath,unzippath,outputpath,logpath,fromd,tod,sn,response.statusCode, urlStockinfo, arrYahooSymbols, yahoo_min, n,days);
}
else
{
downloadgoogleieod(count,baseurl,downloadpath,unzippath,outputpath,logpath,fromd,tod,sn,404, urlStockinfo, arrYahooSymbols, yahoo_min, n,days);
}
}else
{
downloadgoogleieod(count,baseurl,downloadpath,unzippath,outputpath,logpath,fromd,tod,sn,404, urlStockinfo, arrYahooSymbols, yahoo_min, n,days);
}
}else
{
downloadgoogleieod(count,baseurl,downloadpath,unzippath,outputpath,logpath,fromd,tod,sn,404, urlStockinfo, arrYahooSymbols, yahoo_min, n,days);
}
});
}
function downloadgoogleieod(count,baseurl,downloadpath,unzippath,outputpath,logpath,fromd,tod,sn,statuscode, urlStockinfo, arrYahooSymbols, yahoo_min, n,days)
{
var fileName = "";
if(yahoo_min == "1")
{
fileName = downloadpath+"temp_yahoo/googleieod_1min_"+arrYahooSymbols[n].split(':')[1]+".csv";
}
if(yahoo_min == "5")
fileName = downloadpath+"temp_yahoo/googleieod_5min_"+arrYahooSymbols[n].split(':')[1]+".csv";
var http = require('http'),
fs = require('fs'),
request = require('request');
if(statuscode==200){
var out = fs.createWriteStream(fileName);
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",
"Accept-Encoding": "text/html",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"Cookie": "cookie"
}
}
);
req.pipe(out);
req.on('error',function(err){
console.log('\n err'+err.stack);
});
req.on('end', function()
{
Ext.getCmp('pbar3').updateText(fileName.split("/")[fileName.split("/").length-1]+' downloaded...');
document.getElementById("om").innerHTML+="<br/>"+fileName.split('/')[fileName.split('/').length-1]+" downloaded...";
n++;
if(arrYahooSymbols.length > n)
{
loadprogressbar();
setTimeout(function(){
downloadAndProcessGoogleIEOD(count,baseurl,downloadpath,unzippath,outputpath,logpath,fromd,tod,sn,arrYahooSymbols, yahoo_min, n,days);
},100);
}else
{
loadprogressbar();
setTimeout(function(){
processGoogleIEODFiles(count,baseurl,downloadpath,unzippath,outputpath,logpath,fromd,tod,sn,arrYahooSymbols, yahoo_min, fileName, 0);
},1000);
}
});
}
else
{
console.log('\n ERROR while downloading '+arrYahooSymbols[n]);
}
}
function processGoogleIEODFiles(count,baseurl,downloadpath,unzippath,outputpath,logpath,fromd,tod,sn,arrYahooSymbols, yahoo_min, fileName, n)
{
var fileName1 = "";
if(yahoo_min == "1")
{
fileName1 = downloadpath+"temp_yahoo/googleieod_1min_"+arrYahooSymbols[n].split(':')[1]+".csv";
}
if(yahoo_min == "60")
{
fileName1 = downloadpath+"temp_yahoo/googleieod_60min_"+arrYahooSymbols[n].split(':')[1]+".csv";
}
if(yahoo_min == "5")
fileName1 = downloadpath+"temp_yahoo/googleieod_5min_"+arrYahooSymbols[n].split(':')[1]+".csv";
var fs = require('fs');
var csv = require('ya-csv');
var async = require('async');
async.parallel({
data1 : function(callback){
if (fs.existsSync(fileName1)) {
fs.readFile(fileName1,'utf-8', function(err, data){
callback(err, data);
});
}else
{
fs.readdir(downloadpath, function(err, files){
callback(err,'0');
});
}
}
}, function(err, result){
if(err) throw err;
if (fs.existsSync(fileName1)) {
var arrRow = new Array();
var strSymbol = arrYahooSymbols[n].split(':')[1];
var strCompanyName = arrYahooSymbols[n].split(':')[1];
arrRow = result['data1'].split('\n');
var arrFileData = new Array();
if(arrRow.length > 7)
{
for(var i=7 ; i<arrRow.length-1;i++)
{
var tempArr = arrRow[i].split(',');
arrFileData.push(tempArr);
}
var filename = "";
if(yahoo_min == "1")
{
filename = "googleieod_1min"+strSymbol+".csv";
}
if(yahoo_min == "5")
filename = "googleieod_5min"+strSymbol+".csv";
if(yahoo_min == "60")
filename = "googleieod_60min"+strSymbol+".csv";
var header='TICKER,NAME,DATE,TIME,OPEN,HIGH,LOW,CLOSE,VOLUME,OPENINT';
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1;
var yyyy = today.getFullYear();
if(dd<10){
dd='0'+dd
}
if(mm<10){
mm='0'+mm
}
var today = mm+'/'+dd+'/'+yyyy;
if(!fs.existsSync(outputpath+filename)){
fs.writeFile(outputpath+filename, header+'\n', function (err)
{
var googlehr = "0";
var googlemin = "0";
for(var i=0;i<baseurl.length;i++)
{
if(baseurl[i].toString().split(',')[0] == "googlehr")
googlehr = baseurl[i].toString().split(',')[1].toString();
if(baseurl[i].toString().split(',')[0] == "googlemin")
googlemin = baseurl[i].toString().split(',')[1].toString();
}
if (err) throw err;
var timestamp
for(var i=0 ; i<arrFileData.length;i++)
{
if(arrFileData[i][0].search("a")>=0)
{
timestamp=arrFileData[i][0];
timestamp=timestamp.substr(1);
timestamp=parseInt(timestamp.toString());
}
var d = new Date();
var date = new Date(timestamp*1000);
var yr=date.getFullYear();
var mnth=date.getMonth()+1;
var dat=date.getDate();
if(mnth<10)
mnth='0'+mnth;
if(dat<10)
dat='0'+dat;
date.setHours(date.getHours()+parseInt(googlehr));
var ghr = date.getHours();
date.setMinutes(date.getMinutes()+parseInt(googlemin));
var gmin = date.getMinutes();
fs.appendFileSync(outputpath+filename,strSymbol+','+strCompanyName+','+yr+''+mnth+''+dat+','+ghr+':'+gmin+':'+date.getSeconds()+','+arrFileData[i][4]+','+arrFileData[i][2]+','+arrFileData[i][3]+','+arrFileData[i][1]+','+arrFileData[i][5]+','+'0'+'\n','UTF-8' ,function (err) {
if (err) throw err;
});
timestamp=timestamp+(parseInt(yahoo_min)*60);
}
});
}
Ext.getCmp('pbar3').updateText('Processing '+filename+' completed');
document.getElementById("om").innerHTML+='<br/>Processing '+filename+' completed';
}
n++;
if(arrYahooSymbols.length > n)
{
loadprogressbar();
setTimeout(function(){
processGoogleIEODFiles(count,baseurl,downloadpath,unzippath,outputpath,logpath,fromd,tod,sn,arrYahooSymbols, yahoo_min, fileName, n);
},1000);
}else
{
sn++;
callfun(count,baseurl,downloadpath,unzippath,outputpath,logpath,fromd,tod,sn);
}
}
} );
}