15
Fetch Statistics from the Yahoo Finance and save it into a Google Sheet document

Fetch Company's statististics from Yahoo Finance and save it info a Google Sheet Document

Embed Size (px)

DESCRIPTION

Fetch Statistics from Yahoo Finance and save it info a Google Sheet Document. If you want to have the source code please don't feel shy and send me an email at [email protected] or [email protected] Thanks.

Citation preview

Page 1: Fetch Company's statististics from Yahoo Finance and save it info a Google Sheet Document

Fetch Statistics from the Yahoo Finance and save it

into a Google Sheet document

Page 2: Fetch Company's statististics from Yahoo Finance and save it info a Google Sheet Document

• An Engineering Student at the International Institute of Technology

• Node.js Developer• Article Writer at CodeProject.com

About me

Page 3: Fetch Company's statististics from Yahoo Finance and save it info a Google Sheet Document

• A powerful platform to let you run JS on the server side• How? Uses Google’s V8 Engine• V8 is built in C• V8 is the fatest JS Engine on the planet• Great way to build modern web apps on both Client and

Server side!

What is Node.js?

Page 4: Fetch Company's statististics from Yahoo Finance and save it info a Google Sheet Document

Timeline

2009 2010 2011 2012

Jan 2009Created Ryan Dahl

April 2010 Heroku launches node support

Nov 2011 Windows Azure support

EBay releases API built on node

Cloud9IDE azuresupport

Oct 2011 node.js overtakes Ruby as most popular repo on gitHub

Walmart Launch mobile site on node.js

Feb 2012 App Harbour support

July 2011

LinkedIn adopts node for mobile platform

port to Windows

IISNode

July 2010 Yammer adopts node.js

Nov 2010 Cloud9IDE launches

Page 5: Fetch Company's statististics from Yahoo Finance and save it info a Google Sheet Document

Companies support Node.js

• Yahoo!• Microsoft • LinkedIn• Ebay• Fidelizoo• Paypal• CHESS• …

Page 6: Fetch Company's statististics from Yahoo Finance and save it info a Google Sheet Document

What Can I Do in Node?

• Anything you want!• Chat servers, Analytics & Crazy fast backends• Socket.io library is a wicked way to build real time apps• Build a social Network! LinkedIn, Dropbox all using Node.js

Page 7: Fetch Company's statististics from Yahoo Finance and save it info a Google Sheet Document

What Can’t I Do in Node?

• Contradicts previous slide but Node.js is not a web framework i.e Sinatra Modules for node.js make it into web framework i.e Express Node.js is not Multi-threaded A single thread to rule them all

Page 8: Fetch Company's statististics from Yahoo Finance and save it info a Google Sheet Document

Non-Blocking? Blocking? I’m so confused

• By introducing callbacks. Node can move on to other requests and whenever the callback is called, node will process is.

• You should read non-blocking code as « put function and params in queue and fire callback when you reach the end of the queue »

• Blocking= return Non-Blocking= no return. Only callbacks

Page 9: Fetch Company's statististics from Yahoo Finance and save it info a Google Sheet Document

Fetch Statistics from the Yahoo Finance

• We have to fetch data from the link shown below:

http://finance.yahoo.com/q/ks?s=LVS

The Company in our example is LVS.

Page 10: Fetch Company's statististics from Yahoo Finance and save it info a Google Sheet Document

• You need to install Node.js Of course and it 3 packages: npm install request – So we could work with URLs in an easy

way. npm install cheerio – jQuery for the server side. This will make

the code 10x shorter. npm install edit-google-spreadsheet – to integrate with

Google docs/sheets with 2-3 lines of code.

Fetch Statistics from the Yahoo Finance

Page 11: Fetch Company's statististics from Yahoo Finance and save it info a Google Sheet Document

Fetch Statistics from the Yahoo Finance

• // Some parameters • var ticker = "LVS";• var yUrl = "http://finance.yahoo.com/q/ks?s=" + ticker;• var financeDetails = new Array();• var keyStr = new Array();

Page 12: Fetch Company's statististics from Yahoo Finance and save it info a Google Sheet Document

• // The main call to fetch the data, parse it and work on it.

• request(yUrl, function (error, response, body) {• if (!error && response.statusCode == 200) {• var $ = cheerio.load(body);• // the keys - We get them from a certain class attribute• var td = $('.yfnc_tablehead1');• $(td).each(function(j, val) {• keyStr[j] = $(val).text();• });

Fetch Statistics from the Yahoo Finance

Page 13: Fetch Company's statististics from Yahoo Finance and save it info a Google Sheet Document

Working with Google Sheet Document

• // upload our data to Google sheet• Spreadsheet.create({• debug: true,• username: 'TODO-fill',• password: 'TODO-fill',• debug: true,• spreadsheetName: 'TODO-yourSheetName',• worksheetName: 'TODO-Sheet1orAbetterName',• callback: sheetReady• });

Page 14: Fetch Company's statististics from Yahoo Finance and save it info a Google Sheet Document

Demo

Page 15: Fetch Company's statististics from Yahoo Finance and save it info a Google Sheet Document

Thank you

[email protected]