ruboty-weather 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ruboty/handlers/weather.rb +1 -1
- data/lib/ruboty/weather/client.rb +34 -11
- data/lib/ruboty/weather/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ecbe7a1112b83e2d5aeda9649e62793f8f408d69
|
4
|
+
data.tar.gz: 946ee44d3ed0e50daf5eb894da8c2eea3666714d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d2cf18cd5ff5ec4d043b6c43dbcca1ac6da746c65273af1f4e24f73367f0cc28e0d5d703a0a7a59bd0287682ae8b6f377dfb9cb602c45defba2acc9ad0d63be7
|
7
|
+
data.tar.gz: 397a1215d30f887aec4a58eca6f2c50f3dbe03abeead556307175c11d34d4844d94fecf8635bfe30819a20078e61a1044679e26df06eaadb37a49dd53133dbc7
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Ruboty
|
2
2
|
module Handlers
|
3
3
|
class Weather < Base
|
4
|
-
on /weather
|
4
|
+
on /weather/, name: "weather", description: "Fetch weather info from livedoor API"
|
5
5
|
|
6
6
|
def weather(message)
|
7
7
|
message.reply(fetch)
|
@@ -5,12 +5,6 @@ module Ruboty
|
|
5
5
|
module Weather
|
6
6
|
class Client
|
7
7
|
LIVEDOOR_WEATHER_API_URL = 'http://weather.livedoor.com/forecast/webservice/json/v1'
|
8
|
-
#TODO parse this http://weather.livedoor.com/forecast/rss/primary_area.xml
|
9
|
-
CITIES = {
|
10
|
-
tokyo: 130010,
|
11
|
-
chiba: 120010,
|
12
|
-
yokohama: 140010
|
13
|
-
}
|
14
8
|
|
15
9
|
def initialize
|
16
10
|
@client = Faraday.new do |connection|
|
@@ -21,7 +15,15 @@ module Ruboty
|
|
21
15
|
|
22
16
|
def get(city_code=default_city)
|
23
17
|
response = @client.get("#{url}?city=#{city_code}").body
|
24
|
-
|
18
|
+
|
19
|
+
forecasts = response['forecasts']
|
20
|
+
today = forecasts[0]
|
21
|
+
tomorrow = forecasts[1]
|
22
|
+
|
23
|
+
today_forecast = "#{today['date']}: #{emojilize!(today['telop'])} (#{temperature_to_s(today['temperature'])})"
|
24
|
+
tomorrow_forecast = "#{tomorrow['date']}: #{emojilize!(tomorrow['telop'])} (#{temperature_to_s(tomorrow['temperature'])})"
|
25
|
+
|
26
|
+
[today_forecast, tomorrow_forecast].join("\n")
|
25
27
|
end
|
26
28
|
|
27
29
|
private
|
@@ -30,13 +32,34 @@ module Ruboty
|
|
30
32
|
LIVEDOOR_WEATHER_API_URL
|
31
33
|
end
|
32
34
|
|
33
|
-
def cities
|
34
|
-
CITIES
|
35
|
-
end
|
36
|
-
|
37
35
|
def default_city
|
38
36
|
ENV['RUBOTY_WEATHER_CITY'] || 130010 #tokyo
|
39
37
|
end
|
38
|
+
|
39
|
+
def emojilize!(telop)
|
40
|
+
|
41
|
+
telop.gsub!(/時々/, "\u{2194}")
|
42
|
+
telop.gsub!(/のち/, "\u{27A1}")
|
43
|
+
|
44
|
+
emojis = {
|
45
|
+
"晴" => "\u{2600}",
|
46
|
+
"曇" => "\u{2601}",
|
47
|
+
"雨" => "\u{2614}",
|
48
|
+
"雷" => "\u{26A1}",
|
49
|
+
"雪" => "\u{26C4}",
|
50
|
+
}.each do |k, v|
|
51
|
+
telop.gsub!(/#{k}/, v)
|
52
|
+
end
|
53
|
+
|
54
|
+
telop
|
55
|
+
end
|
56
|
+
|
57
|
+
def temperature_to_s(temperature)
|
58
|
+
min = (temperature['min'] ? temperature['min']['celsius'] : '-')
|
59
|
+
max = (temperature['max'] ? temperature['max']['celsius'] : '-')
|
60
|
+
|
61
|
+
"#{min}/#{max}"
|
62
|
+
end
|
40
63
|
end
|
41
64
|
end
|
42
65
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruboty-weather
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryoichi SEKIGUCHI
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruboty
|