Skip to content

Instantly share code, notes, and snippets.

@ShellyShulei
Last active December 13, 2019 15:03
Show Gist options
  • Select an option

  • Save ShellyShulei/a8f0ca977d0efd937296b75b4058b641 to your computer and use it in GitHub Desktop.

Select an option

Save ShellyShulei/a8f0ca977d0efd937296b75b4058b641 to your computer and use it in GitHub Desktop.
Calls the GitHub API to get the star count for an org/user and repository.
name: StockOnline (1)
description: Calls the GitHub API to get the star count for an org/user and repository.
host: EXCEL
api_set: {}
script:
content: |
async function getStockOnline(symbol) {
var API_KEY = "8KOBOUBTEF7RHR21";
const requestURL = `https://www.alphavantage.co/query?function=TIME_SERIES_MONTHLY&symbol=${symbol}&apikey=${API_KEY}`;
const response = await fetch(requestURL);
const data = await response.json();
if (data.hasOwnProperty("Note")) {
throw new Error("API limit reached");
}
if (data.hasOwnProperty("Error Message")) {
throw new Error(data["Error Message"]);
}
let monthlyData = data["Monthly Time Series"];
let dates = Object.keys(monthlyData);
let a = data["Monthly Time Series"][dates[1]]["4. close"];
//let a = dates.forEach(function(item) {
//console.log(dates[0]);
console.log(a);
console.log(requestURL);
return a;
//console.log(["Monthly Time Series"][item]["1. open"]);
//});
}
language: typescript
template:
content: |
<p class="ms-font-m">Executes a simple code snippet.</p>
<button id="run" class="ms-Button">
<span class="ms-Button-label">Run code</span>
</button>
language: HTML
style:
content: ''
language: CSS
libraries: |
https://appsforoffice.microsoft.com/lib/1/hosted/office.js
@types/office-js
core-js@2.4.1/client/core.min.js
name: StockOnline
description: Calls the GitHub API to get the star count for an org/user and repository.
host: EXCEL
api_set: {}
script:
content: |
/**
* Gets the star count for a given org/user and repo. Try =GETSTARCOUNT("officedev","office-js")
* @customfunction
* @param userName Name of org or user.
* @param repoName Name of the repo.
* @return Number of stars.
*/
async function getStockOnline(symbol) {
var API_KEY = "8KOBOUBTEF7RHR21";
const requestURL = `https://www.alphavantage.co/query?function=TIME_SERIES_MONTHLY&symbol=${symbol}&apikey=${API_KEY}`;
const response = await fetch(requestURL);
const data = await response.json();
if (data.hasOwnProperty("Note")) {
throw new Error("API limit reached");
}
if (data.hasOwnProperty("Error Message")) {
throw new Error(data["Error Message"]);
}
let monthlyData = data["Monthly Time Series"];
let dates = Object.keys(monthlyData);
let a = data["Monthly Time Series"][dates[1]]["4. close"];
//let a = dates.forEach(function(item) {
//console.log(dates[0]);
console.log(a);
console.log(requestURL);
return a;
//console.log(["Monthly Time Series"][item]["1. open"]);
//});
}
language: typescript
libraries: |
https://appsforoffice.microsoft.com/lib/1/hosted/office.js
@types/office-js
core-js@2.4.1/client/core.min.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment