-
Notifications
You must be signed in to change notification settings - Fork 0
/
temperatter2.rb
51 lines (40 loc) · 1.42 KB
/
temperatter2.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/ruby
#coding:utf-8
require 'twitter'
require 'pp'
require 'date'
client = Twitter::REST::Client.new do |config|
config.consumer_key = "your consumer key"
config.consumer_secret = "your consumer secret"
config.access_token = "your access token"
config.access_token_secret = "your access token secret"
end
def status1()
res = `./ptemp2`
return {"temp" => res.to_f}
end
def status2()
filename = "/home/pi/tprt2_hi.dat"
te = File.read(filename)
return{"temp2" => te.to_f}
end
s1 = status1()
s2 = status2()
day = Time.now
#puts("#{s1['temp']}")
#puts("#{s2['temp2']}")
tn = s1['temp']
tp = s2['temp2']
if tn > tp
client.update("#{day.hour}時#{day.min}分の気温は"+"#{sprintf("%.1f", tn)}度です。"+"先程より#{sprintf("%.1f", tn - tp)}℃上昇しました。 #Temperatter")
end
if tn < tp
client.update("#{day.hour}時#{day.min}分の気温は"+"#{sprintf("%.1f", tn)}度です。"+"先程より#{sprintf("%.1f", tp - tn)}℃下降しました。 #Temperatter")
end
if tn == tp
client.update("#{day.hour}時#{day.min}分の気温は"+"#{sprintf("%.1f", tn)}度です。"+"先程と変動ありません。 #Temperatter")
end
filename = "/home/pi/tprt2_hi.dat"
File.open(filename,'w') do |file|
file.write("#{sprintf("%.1f", tn)}")
end