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.

577 lines (519 loc) 22.2 kB
/* * This calendar application was forked from Ext Calendar Pro * and contributed to Ext JS as an advanced example of what can * be built using and customizing Ext components and templates. * * If you find this example to be useful you should take a look at * the original project, which has more features, more examples and * is maintained on a regular basis: * * http://ext.ensible.com/products/calendar */ try{ var async = require('async'); var fs = require('fs'); var csv = require('ya-csv'); if(fs.existsSync('settings.csv')) { var path=""; var reader = csv.createCsvFileReader('settings.csv',{'separator': ','}); reader.addListener('data', function(data) { if(data[0]=='datafolder') { path = data[1]; } if(data[0]=='event') { var ca = 0; var bm = 0; if(data[1].search('Corporate_Events')>=0) { ca = 1; } if(data[1].search('Board_Meetings')>=0) { bm =1 } async.parallel ({ data1 : function(callback){ if (fs.existsSync(path+'/events/BM_All_Forthcoming.csv') && bm == 1) { fs.readFile(path+'/events/BM_All_Forthcoming.csv','utf-8', function(err, data){ if(err){console.log(err)} 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){ if(err){console.log(err)} callback(err,'0'); }); } }, data2 : function(callback){ if (fs.existsSync(path+'/events/CA_ALL_FORTHCOMING.csv') && ca == 1) { fs.readFile(path+'/events/CA_ALL_FORTHCOMING.csv','utf-8', function(err, data){ if(err){console.log(err)} 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){ if(err){console.log(err)} callback(err,'0'); }); } } }, function(err, result) { var arrFileData = new Array(); var arrFileDataCA = new Array(); if (bm == 1) { var arrRow = new Array(); arrRow = result['data1'].split('\n'); for(var i=0 ; i<arrRow.length;i++) { var tempArr = arrRow[i].split(','); arrFileData.push(tempArr); } } if (ca == 1) { var arrRowCA = new Array(); arrRowCA = result['data2'].split('\n'); for(var i=0 ; i<arrRowCA.length;i++) { var tempArr1 = arrRowCA[i].split(','); arrFileDataCA.push(tempArr1); } } Ext.define('Ext.calendar.App', { requires: [ 'Ext.Viewport', 'Ext.layout.container.Border', 'Ext.picker.Date', 'Ext.calendar.util.Date', 'Ext.calendar.CalendarPanel', 'Ext.calendar.data.MemoryCalendarStore', 'Ext.calendar.data.MemoryEventStore', //'Ext.calendar.data.Events', 'Ext.calendar.data.Calendars', 'Ext.calendar.form.EventWindow' ], constructor : function() { var M = Ext.calendar.data.EventMappings; var arrRec = new Array(); if(bm == 1) { for(var i=1 ; i<arrFileData.length-1;i++) { for(var i=1 ; i<arrFileData.length-1;i++) { if(arrFileData[i][4] != null && arrFileData[i][4] != "" && typeof arrFileData[i][4] != 'undefined') { var evtFinalDate = ""; var arrTempDate = arrFileData[i][4].toString().split('-'); var evtDate = arrTempDate[0].toString().replace("\"", ""); var evtMonth = getMonth(arrTempDate[1].toString()); var evtYear = arrTempDate[2].toString().replace("\"", ""); evtFinalDate = evtYear+'-'+evtMonth+'-'+evtDate; var rec = new Ext.calendar.data.EventModel(); //var rec2 = new Ext.calendar.data.EventModel(); rec.data[M.Title.name] = 'Company name:'+arrFileData[i][1]+' Event:'+arrFileData[i][3]; rec.data[M.EventId.name] = 1000+i; rec.data[M.CalendarId.name] = 100+i; rec.data[M.StartDate.name] = new Date(evtFinalDate); rec.data[M.EndDate.name] = new Date(evtFinalDate); rec.data[M.Notes.name] = ''; arrRec.push(rec); } } } } if(ca == 1) { for(var i=1 ; i<arrFileDataCA.length-1;i++) { for(var i=1 ; i<arrFileDataCA.length-1;i++) { if(arrFileDataCA[i][6] != null && arrFileDataCA[i][6] != "" && typeof arrFileDataCA[i][6] != 'undefined') { var evtFinalDate = ""; var arrTempDate = arrFileDataCA[i][6].toString().split('-'); var evtDate = arrTempDate[0].toString().replace("\"", ""); var evtMonth = getMonth(arrTempDate[1].toString()); var evtYear = arrTempDate[2].toString().replace("\"", ""); evtFinalDate = evtYear+'-'+evtMonth+'-'+evtDate; var rec = new Ext.calendar.data.EventModel(); //var rec2 = new Ext.calendar.data.EventModel(); rec.data[M.Title.name] = 'Company name:'+arrFileDataCA[i][1]+' Event:'+arrFileDataCA[i][5]; rec.data[M.EventId.name] = 5000+i; rec.data[M.CalendarId.name] = 700+i; rec.data[M.StartDate.name] = new Date(evtFinalDate); rec.data[M.EndDate.name] = new Date(evtFinalDate); rec.data[M.Notes.name] = 'Event'; arrRec.push(rec); } } } } function getMonth(mon){ var month=''; switch(mon) { case 'Jan': month='01'; break; case 'Feb': month='02'; break; case 'Mar': month='03'; break; case 'Apr': month='04'; break; case 'May': month='05'; break; case 'Jun': month='06'; break; case 'Jul': month='07'; break; case 'Aug': month='08'; break; case 'Sep': month='09'; break; case 'Oct': month='10'; break; case 'Nov': month='11'; break; case 'Dec': month='12'; break; } return month; } // Minor workaround for OSX Lion scrollbars this.checkScrollOffset(); // This is an example calendar store that enables event color-coding this.calendarStore = Ext.create('Ext.calendar.data.MemoryCalendarStore', { data: Ext.calendar.data.Calendars.getData() }); // A sample event store that loads static JSON from a local file. Obviously a real // implementation would likely be loading remote data via an HttpProxy, but the // underlying store functionality is the same. this.eventStore = Ext.create('Ext.calendar.data.MemoryEventStore', { data: arrRec }); // This is the app UI layout code. All of the calendar views are subcomponents of // CalendarPanel, but the app title bar and sidebar/navigation calendar are separate // pieces that are composed in app-specific layout code since they could be omitted // or placed elsewhere within the application. Ext.create('Ext.Viewport', { layout: 'border', renderTo: 'calendar-ct', items: [{ id: 'app-header', region: 'north', height: 35, border: false, contentEl: 'app-header-content' },{ id: 'app-center', title: '...', // will be updated to the current view's date range region: 'center', layout: 'border', listeners: { 'afterrender': function(){ Ext.getCmp('app-center').header.addCls('app-center-header'); } }, items: [{ id:'app-west', region: 'west', width: 179, border: false, items: [{ xtype: 'datepicker', id: 'app-nav-picker', cls: 'ext-cal-nav-picker', listeners: { 'select': { fn: function(dp, dt){ Ext.getCmp('app-calendar').setStartDate(dt); }, scope: this } } }] },{ xtype: 'calendarpanel', eventStore: this.eventStore, calendarStore: this.calendarStore, border: false, id:'app-calendar', region: 'center', activeItem: 3, // month view monthViewCfg: { showHeader: true, showWeekLinks: true, showWeekNumbers: true }, listeners: { 'eventclick': { fn: function(vw, rec, el){ this.showEditWindow(rec, el); this.clearMsg(); }, scope: this }, 'eventover': function(vw, rec, el){ //console.log('Entered evt rec='+rec.data.Title+', view='+ vw.id +', el='+el.id); }, 'eventout': function(vw, rec, el){ //console.log('Leaving evt rec='+rec.data.Title+', view='+ vw.id +', el='+el.id); }, 'eventadd': { fn: function(cp, rec){ this.showMsg('Event '+ rec.data.Title +' was added'); }, scope: this }, 'eventupdate': { fn: function(cp, rec){ this.showMsg('Event '+ rec.data.Title +' was updated'); }, scope: this }, 'eventcancel': { fn: function(cp, rec){ // edit canceled }, scope: this }, 'viewchange': { fn: function(p, vw, dateInfo){ if(this.editWin){ this.editWin.hide(); } if(dateInfo){ // will be null when switching to the event edit form so ignore Ext.getCmp('app-nav-picker').setValue(dateInfo.activeDate); this.updateTitle(dateInfo.viewStart, dateInfo.viewEnd); } }, scope: this }, 'dayclick': { fn: function(vw, dt, ad, el){ this.showEditWindow({ StartDate: dt, IsAllDay: ad }, el); this.clearMsg(); }, scope: this }, 'rangeselect': { fn: function(win, dates, onComplete){ this.showEditWindow(dates); this.editWin.on('hide', onComplete, this, {single:true}); this.clearMsg(); }, scope: this }, 'eventmove': { fn: function(vw, rec){ var mappings = Ext.calendar.data.EventMappings, time = rec.data[mappings.IsAllDay.name] ? '' : ' \\a\\t g:i a'; rec.commit(); this.showMsg('Event '+ rec.data[mappings.Title.name] +' was moved to '+ Ext.Date.format(rec.data[mappings.StartDate.name], ('F jS'+time))); }, scope: this }, 'eventresize': { fn: function(vw, rec){ rec.commit(); this.showMsg('Event '+ rec.data.Title +' was updated'); }, scope: this }, 'eventdelete': { fn: function(win, rec){ this.eventStore.remove(rec); this.showMsg('Event '+ rec.data.Title +' was deleted'); }, scope: this }, 'initdrag': { fn: function(vw){ if(this.editWin && this.editWin.isVisible()){ this.editWin.hide(); } }, scope: this } } }] }] }); }, // The edit popup window is not part of the CalendarPanel itself -- it is a separate component. // This makes it very easy to swap it out with a different type of window or custom view, or omit // it altogether. Because of this, it's up to the application code to tie the pieces together. // Note that this function is called from various event handlers in the CalendarPanel above. showEditWindow : function(rec, animateTarget){ if(!this.editWin){ this.editWin = Ext.create('Ext.calendar.form.EventWindow', { calendarStore: this.calendarStore, listeners: { 'eventadd': { fn: function(win, rec){ win.hide(); rec.data.IsNew = false; this.eventStore.add(rec); this.eventStore.sync(); this.showMsg('Event '+ rec.data.Title +' was added'); }, scope: this }, 'eventupdate': { fn: function(win, rec){ win.hide(); rec.commit(); this.eventStore.sync(); this.showMsg('Event '+ rec.data.Title +' was updated'); }, scope: this }, 'eventdelete': { fn: function(win, rec){ this.eventStore.remove(rec); this.eventStore.sync(); win.hide(); this.showMsg('Event '+ rec.data.Title +' was deleted'); }, scope: this }, 'editdetails': { fn: function(win, rec){ win.hide(); Ext.getCmp('app-calendar').showEditForm(rec); } } } }); } this.editWin.show(rec, animateTarget); }, // The CalendarPanel itself supports the standard Panel title config, but that title // only spans the calendar views. For a title that spans the entire width of the app // we added a title to the layout's outer center region that is app-specific. This code // updates that outer title based on the currently-selected view range anytime the view changes. updateTitle: function(startDt, endDt){ var p = Ext.getCmp('app-center'), fmt = Ext.Date.format; if(Ext.Date.clearTime(startDt).getTime() == Ext.Date.clearTime(endDt).getTime()){ p.setTitle(fmt(startDt, 'F j, Y')); } else if(startDt.getFullYear() == endDt.getFullYear()){ if(startDt.getMonth() == endDt.getMonth()){ p.setTitle(fmt(startDt, 'F j') + ' - ' + fmt(endDt, 'j, Y')); } else{ p.setTitle(fmt(startDt, 'F j') + ' - ' + fmt(endDt, 'F j, Y')); } } else{ p.setTitle(fmt(startDt, 'F j, Y') + ' - ' + fmt(endDt, 'F j, Y')); } }, // This is an application-specific way to communicate CalendarPanel event messages back to the user. // This could be replaced with a function to do "toast" style messages, growl messages, etc. This will // vary based on application requirements, which is why it's not baked into the CalendarPanel. showMsg: function(msg){ Ext.fly('app-msg').update(msg).removeCls('x-hidden'); }, clearMsg: function(){ Ext.fly('app-msg').update('').addCls('x-hidden'); }, // OSX Lion introduced dynamic scrollbars that do not take up space in the // body. Since certain aspects of the layout are calculated and rely on // scrollbar width, we add a special class if needed so that we can apply // static style rules rather than recalculate sizes on each resize. checkScrollOffset: function() { var scrollbarWidth = Ext.getScrollbarSize ? Ext.getScrollbarSize().width : Ext.getScrollBarWidth(); // We check for less than 3 because the Ext scrollbar measurement gets // slightly padded (not sure the reason), so it's never returned as 0. if (scrollbarWidth < 3) { Ext.getBody().addCls('x-no-scrollbar'); } if (Ext.isWindows) { Ext.getBody().addCls('x-win'); } } }, function() { /* * A few Ext overrides needed to work around issues in the calendar */ Ext.form.Basic.override({ reset: function() { var me = this; // This causes field events to be ignored. This is a problem for the // DateTimeField since it relies on handling the all-day checkbox state // changes to refresh its layout. In general, this batching is really not // needed -- it was an artifact of pre-4.0 performance issues and can be removed. //me.batchLayouts(function() { me.getFields().each(function(f) { f.reset(); }); //}); return me; } }); // Currently MemoryProxy really only functions for read-only data. Since we want // to simulate CRUD transactions we have to at the very least allow them to be // marked as completed and successful, otherwise they will never filter back to the // UI components correctly. Ext.data.MemoryProxy.override({ updateOperation: function(operation, callback, scope) { operation.setCompleted(); operation.setSuccessful(); Ext.callback(callback, scope || me, [operation]); }, create: function() { this.updateOperation.apply(this, arguments); }, update: function() { this.updateOperation.apply(this, arguments); }, destroy: function() { this.updateOperation.apply(this, arguments); } }); }); }); } }); } }catch(err) { console.log(err.stack); }