Last active
January 5, 2018 16:45
-
-
Save pedromenezes/89e35ab567af01a37b6ef18a2e01bedf 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 dolarHojePegaCotacao(url, reference){ | |
return parseFloat(UrlFetchApp.fetch(url.replace(/([^\/]+)$/, '$1/') + "cotacao.txt").getContentText().replace(',', '.')); | |
} | |
function refresh() { | |
SpreadsheetApp.getActiveSheet().getActiveCell().setValue("Última atualização: " + new Date().toLocaleString()); | |
} | |
function onOpen(e) { | |
SpreadsheetApp.getUi().createMenu('Dólar Hoje').addItem('Atualizar', 'refresh').addToUi(); | |
} |
@renatoargh, feito! Obrigado!
Só mais uma idéia, para quem preferir pegar a cotação da Foxbit pode usar esse código aqui na funçao de pegar cotação.
function foxbitPegaCotacao() {
var dados = UrlFetchApp.fetch("https://api.blinktrade.com/api/v1/BRL/ticker?crypto_currency=BTC").getContentText();
return JSON.parse(dados).sell
}
Valeu, seu script me ajudou bastante! Abraço
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Eu colocaria a linha 2 para retornar um número assim vai permitir a formatação do campo como moeda:
Trocaria para isso aqui:
return parseFloat(UrlFetchApp.fetch(url.replace(/([^\/]+)$/, '$1/') + "cotacao.txt").getContentText());