weather_hacker 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/weather_hacker.rb +1 -0
- data/lib/weather_hacker/area_data.rb +295 -0
- data/lib/weather_hacker/client.rb +28 -25
- data/lib/weather_hacker/version.rb +1 -1
- metadata +15 -14
data/lib/weather_hacker.rb
CHANGED
@@ -0,0 +1,295 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
class WeatherHacker
|
4
|
+
module AreaData
|
5
|
+
ID_BY_CITY = {
|
6
|
+
"稚内" => 1,
|
7
|
+
"旭川" => 2,
|
8
|
+
"留萌" => 3,
|
9
|
+
"札幌" => 4,
|
10
|
+
"岩見沢" => 5,
|
11
|
+
"倶知安" => 6,
|
12
|
+
"網走" => 7,
|
13
|
+
"北見" => 8,
|
14
|
+
"紋別" => 9,
|
15
|
+
"根室" => 10,
|
16
|
+
"釧路" => 11,
|
17
|
+
"帯広" => 12,
|
18
|
+
"室蘭" => 13,
|
19
|
+
"浦河" => 14,
|
20
|
+
"函館" => 15,
|
21
|
+
"江差" => 16,
|
22
|
+
"青森" => 17,
|
23
|
+
"むつ" => 18,
|
24
|
+
"八戸" => 19,
|
25
|
+
"秋田" => 20,
|
26
|
+
"横手" => 21,
|
27
|
+
"盛岡" => 22,
|
28
|
+
"宮古" => 23,
|
29
|
+
"大船渡" => 24,
|
30
|
+
"仙台" => 25,
|
31
|
+
"白石" => 26,
|
32
|
+
"山形" => 27,
|
33
|
+
"米沢" => 28,
|
34
|
+
"酒田" => 29,
|
35
|
+
"新庄" => 30,
|
36
|
+
"福島" => 31,
|
37
|
+
"小名浜" => 32,
|
38
|
+
"若松" => 33,
|
39
|
+
"水戸" => 54,
|
40
|
+
"土浦" => 55,
|
41
|
+
"宇都宮" => 56,
|
42
|
+
"大田原" => 57,
|
43
|
+
"前橋" => 58,
|
44
|
+
"みなかみ" => 59,
|
45
|
+
"さいたま" => 60,
|
46
|
+
"熊谷" => 61,
|
47
|
+
"秩父" => 62,
|
48
|
+
"東京" => 63,
|
49
|
+
"大島" => 64,
|
50
|
+
"八丈島" => 65,
|
51
|
+
"父島" => 66,
|
52
|
+
"千葉" => 67,
|
53
|
+
"銚子" => 68,
|
54
|
+
"館山" => 69,
|
55
|
+
"横浜" => 70,
|
56
|
+
"小田原" => 71,
|
57
|
+
"甲府" => 75,
|
58
|
+
"河口湖" => 76,
|
59
|
+
"富山" => 44,
|
60
|
+
"伏木" => 45,
|
61
|
+
"金沢" => 46,
|
62
|
+
"輪島" => 47,
|
63
|
+
"福井" => 48,
|
64
|
+
"敦賀" => 49,
|
65
|
+
"新潟" => 50,
|
66
|
+
"長岡" => 51,
|
67
|
+
"高田" => 52,
|
68
|
+
"相川" => 53,
|
69
|
+
"長野" => 72,
|
70
|
+
"松本" => 73,
|
71
|
+
"飯田" => 74,
|
72
|
+
"静岡" => 34,
|
73
|
+
"網代" => 35,
|
74
|
+
"三島" => 36,
|
75
|
+
"浜松" => 37,
|
76
|
+
"名古屋" => 38,
|
77
|
+
"豊橋" => 39,
|
78
|
+
"岐阜" => 40,
|
79
|
+
"高山" => 41,
|
80
|
+
"津" => 42,
|
81
|
+
"尾鷲" => 43,
|
82
|
+
"大津" => 77,
|
83
|
+
"彦根" => 78,
|
84
|
+
"京都" => 79,
|
85
|
+
"舞鶴" => 80,
|
86
|
+
"大阪" => 81,
|
87
|
+
"神戸" => 82,
|
88
|
+
"豊岡" => 83,
|
89
|
+
"奈良" => 84,
|
90
|
+
"風屋" => 85,
|
91
|
+
"和歌山" => 86,
|
92
|
+
"潮岬" => 87,
|
93
|
+
"岡山" => 88,
|
94
|
+
"津山" => 89,
|
95
|
+
"広島" => 90,
|
96
|
+
"庄原" => 91,
|
97
|
+
"松江" => 92,
|
98
|
+
"浜田" => 93,
|
99
|
+
"西郷" => 94,
|
100
|
+
"鳥取" => 95,
|
101
|
+
"米子" => 96,
|
102
|
+
"下関" => 97,
|
103
|
+
"山口" => 98,
|
104
|
+
"柳井" => 99,
|
105
|
+
"萩" => 100,
|
106
|
+
"徳島" => 101,
|
107
|
+
"日和佐" => 102,
|
108
|
+
"高松" => 103,
|
109
|
+
"松山" => 104,
|
110
|
+
"新居浜" => 105,
|
111
|
+
"宇和島" => 106,
|
112
|
+
"高知" => 107,
|
113
|
+
"室戸" => 108,
|
114
|
+
"清水" => 109,
|
115
|
+
"福岡" => 110,
|
116
|
+
"八幡" => 111,
|
117
|
+
"飯塚" => 112,
|
118
|
+
"久留米" => 113,
|
119
|
+
"大分" => 114,
|
120
|
+
"中津" => 115,
|
121
|
+
"日田" => 116,
|
122
|
+
"佐伯" => 117,
|
123
|
+
"長崎" => 118,
|
124
|
+
"佐世保" => 119,
|
125
|
+
"厳原" => 120,
|
126
|
+
"福江" => 121,
|
127
|
+
"佐賀" => 122,
|
128
|
+
"伊万里" => 123,
|
129
|
+
"熊本" => 124,
|
130
|
+
"阿蘇乙姫" => 125,
|
131
|
+
"牛深" => 126,
|
132
|
+
"人吉" => 127,
|
133
|
+
"宮崎" => 128,
|
134
|
+
"延岡" => 129,
|
135
|
+
"都城" => 130,
|
136
|
+
"高千穂" => 131,
|
137
|
+
"鹿児島" => 132,
|
138
|
+
"鹿屋" => 133,
|
139
|
+
"種子島" => 134,
|
140
|
+
"名瀬" => 135,
|
141
|
+
"那覇" => 136,
|
142
|
+
"名護" => 137,
|
143
|
+
"久米島" => 138,
|
144
|
+
"南大東島" => 139,
|
145
|
+
"宮古島" => 140,
|
146
|
+
"石垣島" => 141,
|
147
|
+
"与那国島" => 142
|
148
|
+
}
|
149
|
+
|
150
|
+
PREF_BY_CITY = {
|
151
|
+
"稚内" => "北海",
|
152
|
+
"旭川" => "北海",
|
153
|
+
"留萌" => "北海",
|
154
|
+
"札幌" => "北海",
|
155
|
+
"岩見沢" => "北海",
|
156
|
+
"倶知安" => "北海",
|
157
|
+
"網走" => "北海",
|
158
|
+
"北見" => "北海",
|
159
|
+
"紋別" => "北海",
|
160
|
+
"根室" => "北海",
|
161
|
+
"釧路" => "北海",
|
162
|
+
"帯広" => "北海",
|
163
|
+
"室蘭" => "北海",
|
164
|
+
"浦河" => "北海",
|
165
|
+
"函館" => "北海",
|
166
|
+
"江差" => "北海",
|
167
|
+
"青森" => "青森",
|
168
|
+
"むつ" => "青森",
|
169
|
+
"八戸" => "青森",
|
170
|
+
"秋田" => "秋田",
|
171
|
+
"横手" => "秋田",
|
172
|
+
"盛岡" => "岩手",
|
173
|
+
"宮古" => "岩手",
|
174
|
+
"大船渡" => "岩手",
|
175
|
+
"仙台" => "宮城",
|
176
|
+
"白石" => "宮城",
|
177
|
+
"山形" => "山形",
|
178
|
+
"米沢" => "山形",
|
179
|
+
"酒田" => "山形",
|
180
|
+
"新庄" => "山形",
|
181
|
+
"福島" => "福島",
|
182
|
+
"小名浜" => "福島",
|
183
|
+
"若松" => "福島",
|
184
|
+
"水戸" => "茨城",
|
185
|
+
"土浦" => "茨城",
|
186
|
+
"宇都宮" => "栃木",
|
187
|
+
"大田原" => "栃木",
|
188
|
+
"前橋" => "群馬",
|
189
|
+
"みなかみ" => "群馬",
|
190
|
+
"さいたま" => "埼玉",
|
191
|
+
"熊谷" => "埼玉",
|
192
|
+
"秩父" => "埼玉",
|
193
|
+
"東京" => "東京",
|
194
|
+
"大島" => "東京",
|
195
|
+
"八丈島" => "東京",
|
196
|
+
"父島" => "東京",
|
197
|
+
"千葉" => "千葉",
|
198
|
+
"銚子" => "千葉",
|
199
|
+
"館山" => "千葉",
|
200
|
+
"横浜" => "神奈川",
|
201
|
+
"小田原" => "神奈川",
|
202
|
+
"甲府" => "山梨",
|
203
|
+
"河口湖" => "山梨",
|
204
|
+
"富山" => "富山",
|
205
|
+
"伏木" => "富山",
|
206
|
+
"金沢" => "石川",
|
207
|
+
"輪島" => "石川",
|
208
|
+
"福井" => "福井",
|
209
|
+
"敦賀" => "福井",
|
210
|
+
"新潟" => "新潟",
|
211
|
+
"長岡" => "新潟",
|
212
|
+
"高田" => "新潟",
|
213
|
+
"相川" => "新潟",
|
214
|
+
"長野" => "長野",
|
215
|
+
"松本" => "長野",
|
216
|
+
"飯田" => "長野",
|
217
|
+
"静岡" => "静岡",
|
218
|
+
"網代" => "静岡",
|
219
|
+
"三島" => "静岡",
|
220
|
+
"浜松" => "静岡",
|
221
|
+
"名古屋" => "愛知",
|
222
|
+
"豊橋" => "愛知",
|
223
|
+
"岐阜" => "岐阜",
|
224
|
+
"高山" => "岐阜",
|
225
|
+
"津" => "三重",
|
226
|
+
"尾鷲" => "三重",
|
227
|
+
"大津" => "滋賀",
|
228
|
+
"彦根" => "滋賀",
|
229
|
+
"京都" => "京都",
|
230
|
+
"舞鶴" => "京都",
|
231
|
+
"大阪" => "大阪",
|
232
|
+
"神戸" => "兵庫",
|
233
|
+
"豊岡" => "兵庫",
|
234
|
+
"奈良" => "奈良",
|
235
|
+
"風屋" => "奈良",
|
236
|
+
"和歌山" => "和歌山",
|
237
|
+
"潮岬" => "和歌山",
|
238
|
+
"岡山" => "岡山",
|
239
|
+
"津山" => "岡山",
|
240
|
+
"広島" => "広島",
|
241
|
+
"庄原" => "広島",
|
242
|
+
"松江" => "島根",
|
243
|
+
"浜田" => "島根",
|
244
|
+
"西郷" => "島根",
|
245
|
+
"鳥取" => "鳥取",
|
246
|
+
"米子" => "鳥取",
|
247
|
+
"下関" => "山口",
|
248
|
+
"山口" => "山口",
|
249
|
+
"柳井" => "山口",
|
250
|
+
"萩" => "山口",
|
251
|
+
"徳島" => "徳島",
|
252
|
+
"日和佐" => "徳島",
|
253
|
+
"高松" => "香川",
|
254
|
+
"松山" => "愛媛",
|
255
|
+
"新居浜" => "愛媛",
|
256
|
+
"宇和島" => "愛媛",
|
257
|
+
"高知" => "高知",
|
258
|
+
"室戸" => "高知",
|
259
|
+
"清水" => "高知",
|
260
|
+
"福岡" => "福岡",
|
261
|
+
"八幡" => "福岡",
|
262
|
+
"飯塚" => "福岡",
|
263
|
+
"久留米" => "福岡",
|
264
|
+
"大分" => "大分",
|
265
|
+
"中津" => "大分",
|
266
|
+
"日田" => "大分",
|
267
|
+
"佐伯" => "大分",
|
268
|
+
"長崎" => "長崎",
|
269
|
+
"佐世保" => "長崎",
|
270
|
+
"厳原" => "長崎",
|
271
|
+
"福江" => "長崎",
|
272
|
+
"佐賀" => "佐賀",
|
273
|
+
"伊万里" => "佐賀",
|
274
|
+
"熊本" => "熊本",
|
275
|
+
"阿蘇乙姫" => "熊本",
|
276
|
+
"牛深" => "熊本",
|
277
|
+
"人吉" => "熊本",
|
278
|
+
"宮崎" => "宮崎",
|
279
|
+
"延岡" => "宮崎",
|
280
|
+
"都城" => "宮崎",
|
281
|
+
"高千穂" => "宮崎",
|
282
|
+
"鹿児島" => "鹿児島",
|
283
|
+
"鹿屋" => "鹿児島",
|
284
|
+
"種子島" => "鹿児島",
|
285
|
+
"名瀬" => "鹿児島",
|
286
|
+
"那覇" => "沖縄",
|
287
|
+
"名護" => "沖縄",
|
288
|
+
"久米島" => "沖縄",
|
289
|
+
"南大東島" => "沖縄",
|
290
|
+
"宮古島" => "沖縄",
|
291
|
+
"石垣島" => "沖縄",
|
292
|
+
"与那国島" => "沖縄"
|
293
|
+
}
|
294
|
+
end
|
295
|
+
end
|
@@ -30,12 +30,6 @@ class WeatherHacker
|
|
30
30
|
self.class.get(*args)
|
31
31
|
end
|
32
32
|
|
33
|
-
# set @pref_by_city and @id_by_city
|
34
|
-
def update_area_table
|
35
|
-
hash = get AREA_TABLE_URL
|
36
|
-
parse_area_table(hash)
|
37
|
-
end
|
38
|
-
|
39
33
|
# return city id via zipcode API
|
40
34
|
def city_id_by_zipcode(zipcode)
|
41
35
|
zipcode = zipcode.to_s.tr("0-9", "0-9").tr("-", "").tr("-", "")
|
@@ -44,7 +38,10 @@ class WeatherHacker
|
|
44
38
|
hash = info_by_zipcode(zipcode)
|
45
39
|
city = canonical_city(hash["city"])
|
46
40
|
pref = canonical_pref(hash["state"])
|
47
|
-
|
41
|
+
|
42
|
+
WeatherHacker::AreaData::ID_BY_CITY[city] ||
|
43
|
+
WeatherHacker::AreaData::ID_BY_CITY[pref] ||
|
44
|
+
WeatherHacker::AreaData::ID_BY_PREF[pref]
|
48
45
|
end
|
49
46
|
|
50
47
|
# return like following Hash
|
@@ -64,7 +61,23 @@ class WeatherHacker
|
|
64
61
|
Hash[values.map { |v| v.to_a.flatten }]
|
65
62
|
end
|
66
63
|
|
67
|
-
#
|
64
|
+
# canonical prefecture name
|
65
|
+
# 道東 => 北海道
|
66
|
+
# 道央 => 北海道
|
67
|
+
# 道南 => 北海道
|
68
|
+
# 道北 => 北海道
|
69
|
+
def canonical_pref(name)
|
70
|
+
name = name.gsub(/^道.*/, "北海道")
|
71
|
+
name = name.gsub(/[都道府県]$/, "")
|
72
|
+
name
|
73
|
+
end
|
74
|
+
|
75
|
+
# canonical city name
|
76
|
+
def canonical_city(city)
|
77
|
+
city.gsub(/市$/, "")
|
78
|
+
end
|
79
|
+
|
80
|
+
# use this wehn you want to update AreaData
|
68
81
|
def pref_by_city
|
69
82
|
@pref_by_city ||= begin
|
70
83
|
update_area_table
|
@@ -72,7 +85,7 @@ class WeatherHacker
|
|
72
85
|
end
|
73
86
|
end
|
74
87
|
|
75
|
-
#
|
88
|
+
# use this wehn you want to update AreaData
|
76
89
|
def id_by_city
|
77
90
|
@id_by_city ||= begin
|
78
91
|
update_area_table
|
@@ -80,6 +93,12 @@ class WeatherHacker
|
|
80
93
|
end
|
81
94
|
end
|
82
95
|
|
96
|
+
# set @pref_by_city and @id_by_city
|
97
|
+
def update_area_table
|
98
|
+
hash = get AREA_TABLE_URL
|
99
|
+
parse_area_table(hash)
|
100
|
+
end
|
101
|
+
|
83
102
|
# return typical city's id
|
84
103
|
def id_by_pref
|
85
104
|
@id_by_pref ||= pref_by_city.inject({}) { |hash, item|
|
@@ -112,22 +131,6 @@ class WeatherHacker
|
|
112
131
|
raise ParseError, "Failed to parse area data from API"
|
113
132
|
end
|
114
133
|
|
115
|
-
# canonical prefecture name
|
116
|
-
# 道東 => 北海道
|
117
|
-
# 道央 => 北海道
|
118
|
-
# 道南 => 北海道
|
119
|
-
# 道北 => 北海道
|
120
|
-
def canonical_pref(name)
|
121
|
-
name = name.gsub(/^道.*/, "北海道")
|
122
|
-
name = name.gsub(/[都道府県]$/, "")
|
123
|
-
name
|
124
|
-
end
|
125
|
-
|
126
|
-
# canonical city name
|
127
|
-
def canonical_city(city)
|
128
|
-
city.gsub(/市$/, "")
|
129
|
-
end
|
130
|
-
|
131
134
|
# Custom Error class to raise in parse response from API
|
132
135
|
class ParseError < StandardError; end
|
133
136
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: weather_hacker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-04-
|
12
|
+
date: 2012-04-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement: &
|
16
|
+
requirement: &70181545291080 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 0.9.2
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70181545291080
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: httparty
|
27
|
-
requirement: &
|
27
|
+
requirement: &70181545290660 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70181545290660
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &70181545290200 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70181545290200
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: simplecov
|
49
|
-
requirement: &
|
49
|
+
requirement: &70181545289780 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70181545289780
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: simplecov-vim
|
60
|
-
requirement: &
|
60
|
+
requirement: &70181545289360 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70181545289360
|
69
69
|
description: Library for Livedoor Weather Web Service
|
70
70
|
email:
|
71
71
|
- r7kamura@gmail.com
|
@@ -80,6 +80,7 @@ files:
|
|
80
80
|
- README.md
|
81
81
|
- Rakefile
|
82
82
|
- lib/weather_hacker.rb
|
83
|
+
- lib/weather_hacker/area_data.rb
|
83
84
|
- lib/weather_hacker/client.rb
|
84
85
|
- lib/weather_hacker/version.rb
|
85
86
|
- spec/fixtures/id_by_city.rb
|
@@ -103,7 +104,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
103
104
|
version: '0'
|
104
105
|
segments:
|
105
106
|
- 0
|
106
|
-
hash: -
|
107
|
+
hash: -14138050602801517
|
107
108
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
109
|
none: false
|
109
110
|
requirements:
|
@@ -112,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
113
|
version: '0'
|
113
114
|
segments:
|
114
115
|
- 0
|
115
|
-
hash: -
|
116
|
+
hash: -14138050602801517
|
116
117
|
requirements: []
|
117
118
|
rubyforge_project:
|
118
119
|
rubygems_version: 1.8.15
|