Last active
February 4, 2018 13:10
-
-
Save claudioc/94805ded10a1040280a1e9b9528d17fd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getUpdates() { | |
updateCell("B3", "ripple") | |
updateCell("C3", "bitcoin") | |
updateCell("D3", "ethereum") | |
updateCell("E4", "litecoin") | |
updateCell("F4", "iota") | |
} | |
function updateCell(cell, code) { | |
const response = UrlFetchApp.fetch("https://api.coinmarketcap.com/v1/ticker/" + code + "/?convert=EUR") | |
const data = JSON.parse(response)[0] | |
const sheet = SpreadsheetApp.getActive().getActiveSheet() | |
const range = sheet.getRange(cell) | |
const [ p1, p2 ] = cell.split('') | |
const percRange = sheet.getRange(p1 + ++p2) | |
percRange.setValue(data.percent_change_24h + '%') | |
percRange.setBackground(data.percent_change_24h > 0 ? "#c8e6c9" : "#ffcdd2") | |
range.setValue((+data.price_eur).toFixed(2)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My take on this. Simplified and removed hardcoded column letters, specifying the range instead