concerto_weather 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,558 @@
1
+ /*!
2
+ * owfont-regular 1.0.0 by Deniz Fuchidzhiev - http://websygen.com
3
+ * License - font: SIL OFL 1.1, css: MIT License
4
+ */
5
+ /* FONT PATH
6
+ * -------------------------- */
7
+ @font-face {
8
+ font-family: 'owfont';
9
+ src: font-url('concerto_weather/owfont-regular.eot?v=1.0.0');
10
+ src: font-url('concerto_weather/owfont-regular.eot?#iefix&v=1.0.0') format('embedded-opentype'),
11
+ font-url('concerto_weather/owfont-regular.woff') format('woff'),
12
+ font-url('concerto_weather/owfont-regular.ttf') format('truetype'),
13
+ font-url('concerto_weather/owfont-regular.svg#owf-regular') format('svg');
14
+ font-weight: normal;
15
+ font-style: normal;
16
+ }
17
+ .owf {
18
+ display: inline-block;
19
+ font: normal normal normal 14px/1 owfont;
20
+ font-size: inherit;
21
+ text-rendering: auto;
22
+ -webkit-font-smoothing: antialiased;
23
+ -moz-osx-font-smoothing: grayscale;
24
+ transform: translate(0, 0);
25
+ }
26
+ /* makes the font 33% larger relative to the icon container */
27
+ .owf-lg {
28
+ font-size: 1.33333333em;
29
+ line-height: 0.75em;
30
+ vertical-align: -15%;
31
+ }
32
+ .owf-2x {
33
+ font-size: 2em;
34
+ }
35
+ .owf-3x {
36
+ font-size: 3em;
37
+ }
38
+ .owf-4x {
39
+ font-size: 4em;
40
+ }
41
+ .owf-5x {
42
+ font-size: 5em;
43
+ }
44
+ .owf-fw {
45
+ width: 1.28571429em;
46
+ text-align: center;
47
+ }
48
+ .owf-ul {
49
+ padding-left: 0;
50
+ margin-left: 2.14285714em;
51
+ list-style-type: none;
52
+ }
53
+ .owf-ul > li {
54
+ position: relative;
55
+ }
56
+ .owf-li {
57
+ position: absolute;
58
+ left: -2.14285714em;
59
+ width: 2.14285714em;
60
+ top: 0.14285714em;
61
+ text-align: center;
62
+ }
63
+ .owf-li.owf-lg {
64
+ left: -1.85714286em;
65
+ }
66
+ .owf-border {
67
+ padding: .2em .25em .15em;
68
+ border: solid 0.08em #eeeeee;
69
+ border-radius: .1em;
70
+ }
71
+ .owf-pull-right {
72
+ float: right;
73
+ }
74
+ .owf-pull-left {
75
+ float: left;
76
+ }
77
+ .owf.owf-pull-left {
78
+ margin-right: .3em;
79
+ }
80
+ .owf.owf-pull-right {
81
+ margin-left: .3em;
82
+ }
83
+
84
+ /* owfont uses the Unicode Private Use Area (PUA) to ensure screen
85
+ readers do not read off random characters that represent icons */
86
+
87
+ /* Weather Condition Codes */
88
+
89
+ /* Thunderstorm - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
90
+
91
+ /* thunderstorm with light rain */
92
+ .owf-200:before,
93
+ .owf-200-d:before,
94
+ .owf-200-n:before {
95
+ content: "\EB28";
96
+ }
97
+ /* thunderstorm with rain */
98
+ .owf-201:before,
99
+ .owf-201-d:before,
100
+ .owf-201-n:before {
101
+ content: "\EB29";
102
+ }
103
+ /* thunderstorm with heavy rain */
104
+ .owf-202:before,
105
+ .owf-202-d:before,
106
+ .owf-202-n:before {
107
+ content: "\EB2A";
108
+ }
109
+ /* light thunderstorm */
110
+ .owf-210:before,
111
+ .owf-210-d:before,
112
+ .owf-210-n:before {
113
+ content: "\EB32";
114
+ }
115
+ /* thunderstorm */
116
+ .owf-211:before,
117
+ .owf-211-d:before,
118
+ .owf-211-n:before {
119
+ content: "\EB33";
120
+ }
121
+ /* heavy thunderstorm */
122
+ .owf-212:before,
123
+ .owf-212-d:before,
124
+ .owf-212-n:before {
125
+ content: "\EB34";
126
+ }
127
+ /* ragged thunderstorm */
128
+ .owf-221:before,
129
+ .owf-221-d:before,
130
+ .owf-221-n:before {
131
+ content: "\EB3D";
132
+ }
133
+ /* thunderstorm with light drizzle */
134
+ .owf-230:before,
135
+ .owf-230-d:before,
136
+ .owf-230-n:before {
137
+ content: "\EB46";
138
+ }
139
+ /* thunderstorm with drizzle */
140
+ .owf-231:before,
141
+ .owf-231-d:before,
142
+ .owf-231-n:before {
143
+ content: "\EB47";
144
+ }
145
+ /* thunderstorm with heavy drizzle */
146
+ .owf-232:before,
147
+ .owf-232-d:before,
148
+ .owf-232-n:before {
149
+ content: "\EB48";
150
+ }
151
+
152
+ /* Drizzle - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
153
+
154
+ /* light intensity drizzle */
155
+ .owf-300:before,
156
+ .owf-300-d:before,
157
+ .owf-300-n:before {
158
+ content: "\EB8C";
159
+ }
160
+ /* drizzle */
161
+ .owf-301:before,
162
+ .owf-301-d:before,
163
+ .owf-301-n:before {
164
+ content: "\EB8D";
165
+ }
166
+ /* heavy intensity drizzle */
167
+ .owf-302:before,
168
+ .owf-302-d:before,
169
+ .owf-302-n:before {
170
+ content: "\EB8E";
171
+ }
172
+ /* light intensity drizzle rain */
173
+ .owf-310:before,
174
+ .owf-310-d:before,
175
+ .owf-310-n:before {
176
+ content: "\EB96";
177
+ }
178
+ /* drizzle rain */
179
+ .owf-311:before,
180
+ .owf-311-d:before,
181
+ .owf-311-n:before {
182
+ content: "\EB97";
183
+ }
184
+ /* heavy intensity drizzle rain */
185
+ .owf-312:before,
186
+ .owf-312-d:before,
187
+ .owf-312-n:before {
188
+ content: "\EB98";
189
+ }
190
+ /* shower rain and drizzle */
191
+ .owf-313:before,
192
+ .owf-313-d:before,
193
+ .owf-313-n:before {
194
+ content: "\EB99";
195
+ }
196
+ /* heavy shower rain and drizzle*/
197
+ .owf-314:before,
198
+ .owf-314-d:before,
199
+ .owf-314-n:before {
200
+ content: "\EB9A";
201
+ }
202
+ /* shower drizzle */
203
+ .owf-321:before,
204
+ .owf-321-d:before,
205
+ .owf-321-n:before {
206
+ content: "\EBA1";
207
+ }
208
+
209
+ /* Rain - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
210
+
211
+ /* light rain */
212
+ .owf-500:before,
213
+ .owf-500-d:before,
214
+ .owf-500-n:before {
215
+ content: "\EC54";
216
+ }
217
+ /* moderate rain */
218
+ .owf-501:before,
219
+ .owf-501-d:before,
220
+ .owf-501-n:before {
221
+ content: "\EC55";
222
+ }
223
+ /* heavy intensity rain */
224
+ .owf-502:before,
225
+ .owf-502-d:before,
226
+ .owf-502-n:before {
227
+ content: "\EC56";
228
+ }
229
+ /* very heavy rain */
230
+ .owf-503:before,
231
+ .owf-503-d:before,
232
+ .owf-503-n:before {
233
+ content: "\EC57";
234
+ }
235
+ /* extreme rain */
236
+ .owf-504:before,
237
+ .owf-504-d:before,
238
+ .owf-504-n:before {
239
+ content: "\EC58";
240
+ }
241
+ /* freezing rain */
242
+ .owf-511:before,
243
+ .owf-511-d:before,
244
+ .owf-511-n:before {
245
+ content: "\EC5F";
246
+ }
247
+ /* light intensity shower rain */
248
+ .owf-520:before,
249
+ .owf-520-d:before,
250
+ .owf-520-n:before {
251
+ content: "\EC68";
252
+ }
253
+ /* shower rain */
254
+ .owf-521:before,
255
+ .owf-521-d:before,
256
+ .owf-521-n:before {
257
+ content: "\EC69";
258
+ }
259
+ /* heavy intensity shower rain */
260
+ .owf-522:before,
261
+ .owf-522-d:before,
262
+ .owf-522-n:before {
263
+ content: "\EC6A";
264
+ }
265
+ /* ragged shower rain */
266
+ .owf-531:before,
267
+ .owf-531-d:before,
268
+ .owf-531-n:before {
269
+ content: "\EC73";
270
+ }
271
+
272
+ /* Snow - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
273
+
274
+ /* light snow */
275
+ .owf-600:before,
276
+ .owf-600-d:before,
277
+ .owf-600-n:before {
278
+ content: "\ECB8";
279
+ }
280
+ /* snow */
281
+ .owf-601:before,
282
+ .owf-601-d:before,
283
+ .owf-601-n:before {
284
+ content: "\ECB9";
285
+ }
286
+ /* heavy snow */
287
+ .owf-602:before,
288
+ .owf-602-d:before,
289
+ .owf-602-n:before {
290
+ content: "\ECBA";
291
+ }
292
+ /* sleet */
293
+ .owf-611:before,
294
+ .owf-611-d:before,
295
+ .owf-611-n:before {
296
+ content: "\ECC3";
297
+ }
298
+ /* shower sleet */
299
+ .owf-612:before,
300
+ .owf-612-d:before,
301
+ .owf-612-n:before {
302
+ content: "\ECC4";
303
+ }
304
+ /* light rain and snow */
305
+ .owf-615:before,
306
+ .owf-615-d:before,
307
+ .owf-615-n:before {
308
+ content: "\ECC7";
309
+ }
310
+ /* rain and snow */
311
+ .owf-616:before,
312
+ .owf-616-d:before,
313
+ .owf-616-n:before {
314
+ content: "\ECC8";
315
+ }
316
+ /* light shower snow */
317
+ .owf-620:before,
318
+ .owf-620-d:before,
319
+ .owf-620-n:before {
320
+ content: "\ECCC";
321
+ }
322
+ /* shower snow */
323
+ .owf-621:before,
324
+ .owf-621-d:before,
325
+ .owf-621-n:before {
326
+ content: "\ECCD";
327
+ }
328
+ /* heavy shower snow */
329
+ .owf-622:before,
330
+ .owf-622-d:before,
331
+ .owf-622-n:before {
332
+ content: "\ECCE";
333
+ }
334
+
335
+ /* Atmosphere - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
336
+
337
+ /* mist */
338
+ .owf-701:before,
339
+ .owf-701-d:before,
340
+ .owf-701-n:before {
341
+ content: "\ED1D";
342
+ }
343
+ /* smoke */
344
+ .owf-711:before,
345
+ .owf-711-d:before,
346
+ .owf-711-n:before {
347
+ content: "\ED27";
348
+ }
349
+ /* haze */
350
+ .owf-721:before,
351
+ .owf-721-d:before,
352
+ .owf-721-n:before {
353
+ content: "\ED31";
354
+ }
355
+ /* Sand/Dust Whirls */
356
+ .owf-731:before,
357
+ .owf-731-d:before,
358
+ .owf-731-n:before {
359
+ content: "\ED3B";
360
+ }
361
+ /* Fog */
362
+ .owf-741:before,
363
+ .owf-741-d:before,
364
+ .owf-741-n:before {
365
+ content: "\ED45";
366
+ }
367
+ /* sand */
368
+ .owf-751:before,
369
+ .owf-751-d:before,
370
+ .owf-751-n:before {
371
+ content: "\ED4F";
372
+ }
373
+ /* dust */
374
+ .owf-761:before,
375
+ .owf-761-d:before,
376
+ .owf-761-n:before {
377
+ content: "\ED59";
378
+ }
379
+ /* VOLCANIC ASH */
380
+ .owf-762:before,
381
+ .owf-762-d:before,
382
+ .owf-762-n:before {
383
+ content: "\ED5A";
384
+ }
385
+ /* SQUALLS */
386
+ .owf-771:before,
387
+ .owf-771-d:before,
388
+ .owf-771-n:before {
389
+ content: "\ED63";
390
+ }
391
+ /* TORNADO */
392
+ .owf-781:before,
393
+ .owf-781-d:before,
394
+ .owf-781-n:before {
395
+ content: "\ED6D";
396
+ }
397
+
398
+ /* Clouds - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
399
+
400
+ /* sky is clear */ /* Calm */
401
+ .owf-800:before,
402
+ .owf-800-d:before,
403
+ .owf-951:before,
404
+ .owf-951-d:before {
405
+ content: "\ED80";
406
+ }
407
+ .owf-800-n:before,
408
+ .owf-951-n:before {
409
+ content: "\F168";
410
+ }
411
+ /* few clouds */
412
+ .owf-801:before,
413
+ .owf-801-d:before {
414
+ content: "\ED81";
415
+ }
416
+ .owf-801-n:before {
417
+ content: "\F169";
418
+ }
419
+ /* scattered clouds */
420
+ .owf-802:before,
421
+ .owf-802-d:before {
422
+ content: "\ED82";
423
+ }
424
+ .owf-802-n:before {
425
+ content: "\F16A";
426
+ }
427
+ /* broken clouds */
428
+ .owf-803:before,
429
+ .owf-803-d:before,
430
+ .owf-803-n:before {
431
+ content: "\ED83";
432
+ }
433
+ /* overcast clouds */
434
+ .owf-804:before,
435
+ .owf-804-d:before,
436
+ .owf-804-n:before {
437
+ content: "\ED84";
438
+ }
439
+
440
+ /* Extreme - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
441
+
442
+ /* tornado */
443
+ .owf-900:before,
444
+ .owf-900-d:before,
445
+ .owf-900-n:before {
446
+ content: "\EDE4";
447
+ }
448
+ /* tropical storm */
449
+ .owf-901:before,
450
+ .owf-901-d:before,
451
+ .owf-901-n:before {
452
+ content: "\EDE5";
453
+ }
454
+ /* hurricane */
455
+ .owf-902:before,
456
+ .owf-902-d:before,
457
+ .owf-902-n:before {
458
+ content: "\EDE6";
459
+ }
460
+ /* cold */
461
+ .owf-903:before,
462
+ .owf-903-d:before,
463
+ .owf-903-n:before {
464
+ content: "\EDE7";
465
+ }
466
+ /* hot */
467
+ .owf-904:before,
468
+ .owf-904-d:before,
469
+ .owf-904-n:before {
470
+ content: "\EDE8";
471
+ }
472
+ /* windy */
473
+ .owf-905:before,
474
+ .owf-905-d:before,
475
+ .owf-905-n:before {
476
+ content: "\EDE9";
477
+ }
478
+ /* hail */
479
+ .owf-906:before,
480
+ .owf-906-d:before,
481
+ .owf-906-n:before {
482
+ content: "\EDEA";
483
+ }
484
+
485
+ /* Additional - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
486
+
487
+ /* Setting */
488
+ .owf-950:before,
489
+ .owf-950-d:before,
490
+ .owf-950-n:before {
491
+ content: "\EE16";
492
+ }
493
+ /* Light breeze */
494
+ .owf-952:before,
495
+ .owf-952-d:before,
496
+ .owf-952-n:before {
497
+ content: "\EE18";
498
+ }
499
+ /* Gentle Breeze */
500
+ .owf-953:before,
501
+ .owf-953-d:before,
502
+ .owf-953-n:before {
503
+ content: "\EE19";
504
+ }
505
+ /* Moderate breeze */
506
+ .owf-954:before,
507
+ .owf-954-d:before,
508
+ .owf-954-n:before {
509
+ content: "\EE1A";
510
+ }
511
+ /* Fresh Breeze */
512
+ .owf-955:before,
513
+ .owf-955-d:before,
514
+ .owf-955-n:before {
515
+ content: "\EE1B";
516
+ }
517
+ /* Strong Breeze */
518
+ .owf-956:before,
519
+ .owf-956-d:before,
520
+ .owf-956-n:before {
521
+ content: "\EE1C";
522
+ }
523
+ /* High wind, near gale */
524
+ .owf-957:before,
525
+ .owf-957-d:before,
526
+ .owf-957-n:before {
527
+ content: "\EE1D";
528
+ }
529
+ /* Gale */
530
+ .owf-958:before,
531
+ .owf-958-d:before,
532
+ .owf-958-n:before {
533
+ content: "\EE1E";
534
+ }
535
+ /* Severe Gale */
536
+ .owf-959:before,
537
+ .owf-959-d:before,
538
+ .owf-959-n:before {
539
+ content: "\EE1F";
540
+ }
541
+ /* Storm */
542
+ .owf-960:before,
543
+ .owf-960-d:before,
544
+ .owf-960-n:before {
545
+ content: "\EE20";
546
+ }
547
+ /* Violent Storm */
548
+ .owf-961:before,
549
+ .owf-961-d:before,
550
+ .owf-961-n:before {
551
+ content: "\EE21";
552
+ }
553
+ /* Hurricane */
554
+ .owf-962:before,
555
+ .owf-962-d:before,
556
+ .owf-962-n:before {
557
+ content: "\EE22";
558
+ }
@@ -2,70 +2,55 @@ class Weather < DynamicContent
2
2
  DISPLAY_NAME = 'Weather'
3
3
 
4
4
  UNITS = {
5
- 'c' => 'Celsius',
6
- 'f' => 'Fahrenheit'
5
+ 'metric' => 'Celsius',
6
+ 'imperial' => 'Fahrenheit'
7
7
  }
8
8
 
9
- validate :woeid_must_exist
10
-
11
9
  def build_content
12
- require 'rss'
10
+ require 'json'
13
11
  require 'net/http'
14
12
 
15
- url = "http://weather.yahooapis.com/forecastrss?w=#{self.config['woeid']}&u=#{self.config['units']}"
16
-
17
- feed = Net::HTTP.get_response(URI.parse(url)).body
18
-
19
- rss = RSS::Parser.parse(feed, false, true)
20
-
21
- weather_data = rss.items.first
22
- sanitized_data = weather_data.description
13
+ # Build request url
14
+ params = {
15
+ q: self.config['location'],
16
+ units: self.config['units'],
17
+ cnt: 1,
18
+ mode: 'json',
19
+ appid: ConcertoConfig['open_weather_map_api_key']
20
+ }
21
+
22
+ url = "http://api.openweathermap.org/data/2.5/forecast/daily?#{params.to_query}"
23
+
24
+ # Make request to OpenWeatherMapAPI
25
+ response = Net::HTTP.get_response(URI.parse(url)).body
26
+ data = JSON.parse(response)
27
+
28
+ # Build HTML using API data
29
+ #<img src='http://api.openweathermap.org/img/w/#{data['list'][0]['weather'][0]['icon']}' />
30
+ rawhtml = "
31
+ <h1> Today in #{data['city']['name']} </h1>
32
+ <div style='float: left; width: 50%'>
33
+ <i class='owf owf-#{data['list'][0]['weather'][0]['id']} owf-5x'></i>
34
+ </div>
35
+ <div style='float: left; width: 50%'>
36
+ <p> High </p>
37
+ <h1> #{data['list'][0]['temp']['max']} &deg;#{UNITS[params[:units]][0]}</h1>
38
+ <p> Low </p>
39
+ <h1> #{data['list'][0]['temp']['min']} &deg;#{UNITS[params[:units]][0]}</h1>
40
+ </div>
41
+ "
42
+
43
+ # Create HtmlText content
23
44
  htmltext = HtmlText.new()
24
- htmltext.name = weather_data.title
25
- rawhtml = "<h1>#{rss.channel.title}</h1><i>#{weather_data.title}</i><p>#{sanitized_data}</p>"
26
- Rails.logger.debug rawhtml
27
- htmltext.data = ActionController::Base.helpers.sanitize(rawhtml, :tags => ['i', 'img', 'b', 'br', 'p', 'h1'])
45
+ htmltext.name = "Today's weather in #{data['city']['name']}"
46
+ htmltext.data = rawhtml
47
+
28
48
  return [htmltext]
29
49
  end
30
50
 
31
51
  # Weather needs a location. Also allow specification of units
32
52
  def self.form_attributes
33
53
  attributes = super()
34
- attributes.concat([:config => [:woeid, :units]])
35
- end
36
-
37
- def woeid_must_exist
38
- if !self.config.nil? # had to add thius because rake dynamic_content:refresh was blowing up on nil object
39
- if self.config['woeid'].empty?
40
- errors.add(:woeid, 'must be specified')
41
- else
42
- data = []
43
- #begin
44
- woeid = URI.escape(self.config['woeid'])
45
- url = URI.escape("http://query.yahooapis.com/v1/public/yql?q=select * from geo.places where woeid = #{woeid} limit 1&format=json")
46
- uri = URI.parse(url)
47
- http = Net::HTTP.new(uri.host, uri.port)
48
- request = Net::HTTP::Get.new(uri.request_uri)
49
- response = http.request(request)
50
- if response.code == '200' #ok
51
- json = response.body
52
- data = ActiveSupport::JSON.decode(json)
53
- end
54
- #rescue
55
- # Rails.logger.debug("Yahoo not reachable @ #{url}.")
56
- # return
57
- #end
58
- if data.empty? || data['query']['count'] == 0
59
- errors.add(:woeid, 'not valid')
60
- else
61
- results = data['query']['results']['place']
62
- info = results['name']
63
- info = info + ', ' + results['admin1']['content'] if !results['admin1']['content'].empty? if !results['admin1'].nil?
64
- info = info + ', ' + results['admin2']['content'] if !results['admin2']['content'].empty? if !results['admin2'].nil?
65
- info = info + ', ' + results['country']['content'] if !results['country']['content'].empty? if !results['country'].nil?
66
- self.config['name'] = info
67
- end
68
- end
69
- end
54
+ attributes.concat([:config => [:location, :units]])
70
55
  end
71
- end
56
+ end
@@ -7,11 +7,9 @@
7
7
  <div class='span4'>
8
8
  <%= form.fields_for :config do |config| %>
9
9
  <div class="clearfix">
10
- <%= config.label :woeid, "Where On Earth ID (WOEID)" %>
10
+ <%= config.label :location, "City" %>
11
11
  <div class="input">
12
- <%= config.text_field :woeid, :placeholder => '2508215', :class => "input-small", :value => @content.config['woeid'] %>
13
- <br/>
14
- <i class="woeid-name"><%= @content.config['name'] %></i>
12
+ <%= config.text_field :location, placeholder: "Sydney", value: @content.config['location'] %>
15
13
  </div>
16
14
  </div>
17
15
  <div class="clearfix">
@@ -1,7 +1,7 @@
1
1
  <dl>
2
2
  <h1>Weather</h1>
3
- <dt>WOEID</dt>
4
- <dd><%= content.config['woeid'] %> - <%= content.config['name'] %></dd>
3
+ <dt>City</dt>
4
+ <dd><%= content.config['location'] %></dd>
5
5
  <dt>Units</dt>
6
6
  <dd><%= Weather::UNITS[content.config['units']] %></dd>
7
7
  <dt>Last Successful Update</dt>
@@ -1 +1 @@
1
- <h1>Weather for <%= content.config['woeid'] %> - <%= content.config['name'] %></h1>
1
+ <h1>Weather for <%= content.config['location'] %></h1>