Skip to content

Instantly share code, notes, and snippets.

@DanEdens
Created May 3, 2020 20:37
Show Gist options
  • Save DanEdens/499924644d9216b2e27149c8e83cbb7d to your computer and use it in GitHub Desktop.
Save DanEdens/499924644d9216b2e27149c8e83cbb7d to your computer and use it in GitHub Desktop.
function to get stock price based on symbol
function getStockQuote(symbol) {const url = `https://finance.google.com/finance?q=${symbol}&output=json`got(url).then(response => {/* Must remove the first three characters of the Google finance text returned to parse JSON.*/const stock = JSON.parse(response.body.substr(3))const quote = stock[0]console.log(`${quote.t} ${quote.l} ${quote.c} (${quote.cp}%)`)}).catch(error => {console.log(error.response.body)})}
@DanEdens
Copy link
Author

DanEdens commented May 3, 2020

export async function getStockQuote(symbol) {const url = https://finance.google.com/finance?q=${symbol}&output=jsongot(url).then(response => {/* Must remove the first three characters of the Google finance text returned to parse JSON.*/const stock = JSON.parse(response.body.substr(3))const quote = stock[0]console.log(${quote.t} ${quote.l} ${quote.c} (${quote.cp}%))}).catch(error => {console.log(error.response.body)})}

@DanEdens
Copy link
Author

DanEdens commented May 3, 2020

//module.exports style
function getStockQuote(symbol) {const url = https://finance.google.com/finance?q=${symbol}&output=jsongot(url).then(response => {/* Must remove the first three characters of the Google finance text returned to parse JSON.*/const stock = JSON.parse(response.body.substr(3))const quote = stock[0]console.log(${quote.t} ${quote.l} ${quote.c} (${quote.cp}%))}).catch(error => {console.log(error.response.body)})}

getStockQuote: getStockQuote,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment