Created
December 21, 2020 11:01
-
-
Save yoshiori/6dc4f5d29275d88ae6fd0d65a68261a9 to your computer and use it in GitHub Desktop.
不快指数だすやつ
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/env ruby | |
require "uri" | |
require "net/http" | |
require "json" | |
token = "xxxx" # https://home.nature.global/ | |
uri = URI.parse("https://api.nature.global/1/devices") | |
http = Net::HTTP.new(uri.host, uri.port) | |
http.use_ssl = true | |
request = Net::HTTP::Get.new(uri.request_uri) | |
request.add_field("Content-Type", "application/json") | |
request.add_field("Authorization", "Bearer #{token}") | |
data = JSON.parse(http.request(request).body).first | |
te = data.dig("newest_events", "te", "val").to_f | |
hu = data.dig("newest_events", "hu", "val").to_f | |
di = (0.81 * te + 0.01 * hu * (0.99 * te - 14.3) + 46.3).to_i | |
case di | |
when 0...55 | |
face = "🥶" | |
text = "寒い" | |
when 55...60 | |
face = "🥶" | |
text = "肌寒い" | |
when 60...65 | |
face = "😐" | |
text = "何も感じない" | |
when 65...70 | |
face = "😊" | |
text = "快い" | |
when 70...75 | |
face = "😐" | |
text = "暑くない" | |
when 75...80 | |
face = "🥵" | |
text = "やや暑い" | |
when 80...85 | |
face = "🥵" | |
p "暑くて汗が出る" | |
when 85...100 | |
face = "🥵" | |
text = "暑くてたまらない" | |
end | |
puts "#{face} #{di}" | |
puts "---" | |
puts text | |
puts "---" | |
puts "🌡 #{te}℃" | |
puts "💧 #{hu.to_i}%" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment