Created
July 3, 2018 07:12
-
-
Save oosawa/bb73e0f104f6a6c24cdff60bf32a15c1 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
// CoinGeckoからモナコイン、Bitzeny、Ethereumの価格を取得して、Discordに投稿 | |
// Google Apps Script用のソースコードです | |
// 毎日1度実行するようにしています | |
function postDiscord() { | |
//payload | |
var payload = { | |
'username': "(*゚ー゚)", | |
'content' : "モナコイン:" + getMONAJPYByCoinGeko() + "/ Bitzeny:" + getZenyJPYByCoinGeko() + "/ Ethereum:" + getETHJPYByCoinGeko() + "\n", // \n で改行 | |
'parse' : "full" | |
}; | |
var options = { | |
'method' : 'post', | |
'contentType' : 'application/json', | |
'payload' : JSON.stringify(payload), | |
'token' : '**** Input YOUR TOKEN *****', | |
'muteHttpExceptions': true | |
}; | |
// Webhook URL | |
var url = 'https://discordapp.com/api/webhooks/..... Input Yout Web hook'; | |
UrlFetchApp.fetch(url, options); | |
} | |
// MONAの価格を返す(過去24時間で、最低円~最高円 | |
function getMONAJPYByCoinGeko() { | |
var url = 'https://api.coingecko.com/api/v3/coins/monacoin'; | |
var json = UrlFetchApp.fetch(url).getContentText(); | |
var jsonData = JSON.parse(json); | |
// 金額 | |
return orgRound(jsonData.market_data.low_24h.jpy, 1000) + "円~" + orgRound(jsonData.market_data.high_24h.jpy, 1000) + "円"; | |
} | |
// Bitzenyの価格を返す(過去24時間で、最低円~最高円 | |
function getZenyJPYByCoinGeko() { | |
var url = 'https://api.coingecko.com/api/v3/coins/bitzeny'; | |
var json = UrlFetchApp.fetch(url).getContentText(); | |
var jsonData = JSON.parse(json); | |
// 金額 | |
return orgRound(jsonData.market_data.low_24h.jpy, 1000) + "円~" + orgRound(jsonData.market_data.high_24h.jpy, 1000) + "円"; | |
} | |
// Ethereumの価格を返す(過去24時間で、最低円~最高円 | |
function getETHJPYByCoinGeko() { | |
var url = 'https://api.coingecko.com/api/v3/coins/ethereum'; | |
var json = UrlFetchApp.fetch(url).getContentText(); | |
var jsonData = JSON.parse(json); | |
// 金額 | |
return orgRound(jsonData.market_data.low_24h.jpy, 1000) + "円~" + orgRound(jsonData.market_data.high_24h.jpy, 1000) + "円"; | |
} | |
// 四捨五入 | |
function orgRound(value, base) { | |
return Math.round(value * base) / base; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment