Last active
December 5, 2020 07:02
-
-
Save moyashi/d5ba29a69d928a178c5080a5f9258c1d to your computer and use it in GitHub Desktop.
Coincheck Market Price
This file contains hidden or 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
#!/usr/bin/ruby | |
# coding: utf-8 | |
# <bitbar.title>Coincheck Market Price</bitbar.title> | |
# <bitbar.version>v1.0</bitbar.version> | |
# <bitbar.author>moyashi</bitbar.author> | |
# <bitbar.author.github>moyashi</bitbar.author.github> | |
# <bitbar.desc>Test</bitbar.desc> | |
# <bitbar.image></bitbar.image> | |
require 'mechanize' | |
require 'json' | |
yaml = File.join(ENV["HOME"], "coincheck.yaml") | |
agent = Mechanize.new | |
#res = agent.get("https://coincheck.com/api/ticker") | |
res = agent.get("https://coincheck.com/api/rate/btc_jpy") | |
json = JSON.parse(res.body) | |
color = "black" | |
difference = 0 | |
#if json && json["last"] then | |
if json && json["rate"] then | |
#current_status = json["last"] | |
current_status = sprintf("%.02f", json["rate"]).to_f | |
if File.exists?(yaml) then | |
previous_status = YAML.load(File.read(yaml)) | |
if (previous_status == false) then | |
previous_status = current_status | |
end | |
difference = sprintf("%.02f", current_status - previous_status).to_f | |
if (difference > 0) then | |
difference = "+" + difference.to_s | |
else | |
difference = difference.to_s | |
end | |
if (previous_status > 0) then | |
if (current_status > previous_status) then | |
color = "green" | |
elsif (current_status == previous_status) then | |
color = "black" | |
else | |
color = "red" | |
end | |
end | |
end | |
File.open(yaml, 'w') {|f| f.write(YAML.dump(current_status)) } | |
puts "#{current_status}(#{difference}) | color=#{color}" | |
end | |
#puts "切り替え表示1" | |
#puts "切り替え表示2" | |
puts "---" | |
puts "ビットコイン(Bitcoin)価格チャート 5分足 | href=https://coincheck.com/ja/exchange/charts/coincheck/btc_jpy/300" | |
puts "ビットコイン(Bitcoin)価格チャート 15分足 | href=https://coincheck.com/ja/exchange/charts/coincheck/btc_jpy/900" | |
puts "ビットコイン(Bitcoin)価格チャート 1時間足 | href=https://coincheck.com/ja/exchange/charts/coincheck/btc_jpy/3600" | |
puts "ビットコイン(Bitcoin)価格チャート 4時間足 | href=https://coincheck.com/ja/exchange/charts/coincheck/btc_jpy/14400" | |
puts "ビットコイン(Bitcoin)価格チャート 24時間足 | href=https://coincheck.com/ja/exchange/charts/coincheck/btc_jpy/86400" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
関連Blog記事: http://hitoriblog.com/?p=50182