tell_weather 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/tell_weather.rb +99 -0
- metadata +43 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a6dd6d8fbbfc53d3e0d7b958343497d58c50bf56
|
4
|
+
data.tar.gz: 1265c1253c8058b73bdbee03241d9eda7cb797d4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 73764b65a177b0ee89ab7226e59e7e105fe54c7b0c60b17d30d1c911fb08f0429d0cab505f9f62986809fc03c5edef077cf5abee999b7a0584ce75ad9df029c1
|
7
|
+
data.tar.gz: ca885a536fde2182f67a5019efd71c876c6fced0545943b24639e3c134f5256b8c1aead164a2a9e4901af40301a109055837ba35736e5e4abd6bf4be06208f6c
|
data/lib/tell_weather.rb
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'net/http'
|
3
|
+
require 'rexml/document'
|
4
|
+
require 'open-uri'
|
5
|
+
include REXML
|
6
|
+
|
7
|
+
class TellWeather
|
8
|
+
def initialize
|
9
|
+
end
|
10
|
+
|
11
|
+
def get_woeid(location)
|
12
|
+
encoded_location= URI::encode(location)
|
13
|
+
url = 'http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20geo.places%20where%20text%3D%22'+encoded_location+'%22&format=xml'
|
14
|
+
xml_data = Net::HTTP.get_response(URI.parse(url)).body
|
15
|
+
@xmldoc = Document.new(xml_data)
|
16
|
+
|
17
|
+
@xmldoc.elements.each("query/results/place/woeid"){
|
18
|
+
|e| return e.text
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
def get_weather_XML(woeid)
|
23
|
+
wurl='http://weather.yahooapis.com/forecastrss?w='+2189783.to_s+'&u=c'
|
24
|
+
wxml= Net::HTTP.get_response(URI.parse(wurl)).body
|
25
|
+
@weather_XML = Document.new(wxml)
|
26
|
+
return @weather_XML
|
27
|
+
end
|
28
|
+
|
29
|
+
def get_wind_chill(woeid)
|
30
|
+
windxml= get_weather_XML(woeid)
|
31
|
+
windxml.elements.each("rss/channel/yweather:wind"){
|
32
|
+
|e| return e.attributes["chill"]
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
def get_wind_direction(woeid)
|
37
|
+
windxml= get_weather_XML(woeid)
|
38
|
+
windxml.elements.each("rss/channel/yweather:wind"){
|
39
|
+
|e| return e.attributes["direction"]
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
def get_wind_speed(woeid)
|
44
|
+
windxml= get_weather_XML(woeid)
|
45
|
+
windxml.elements.each("rss/channel/yweather:wind"){
|
46
|
+
|e| return e.attributes["speed"]
|
47
|
+
}
|
48
|
+
end
|
49
|
+
|
50
|
+
def get_humidity(woeid)
|
51
|
+
windxml= get_weather_XML(woeid)
|
52
|
+
windxml.elements.each("rss/channel/yweather:atmosphere"){
|
53
|
+
|e| return e.attributes["humidity"]
|
54
|
+
}
|
55
|
+
end
|
56
|
+
|
57
|
+
def get_pressure(woeid)
|
58
|
+
windxml= get_weather_XML(woeid)
|
59
|
+
windxml.elements.each("rss/channel/yweather:atmosphere"){
|
60
|
+
|e| return e.attributes["pressure"]
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
def get_sunrise(woeid)
|
65
|
+
windxml= get_weather_XML(woeid)
|
66
|
+
windxml.elements.each("rss/channel/yweather:astronomy"){
|
67
|
+
|e| return e.attributes["sunrise"]
|
68
|
+
}
|
69
|
+
end
|
70
|
+
|
71
|
+
def get_sunset(woeid)
|
72
|
+
windxml= get_weather_XML(woeid)
|
73
|
+
windxml.elements.each("rss/channel/yweather:astronomy"){
|
74
|
+
|e| return e.attributes["sunset"]
|
75
|
+
}
|
76
|
+
end
|
77
|
+
|
78
|
+
def get_latitude(woeid)
|
79
|
+
windxml= get_weather_XML(woeid)
|
80
|
+
windxml.elements.each("rss/channel/item/geo:lat"){
|
81
|
+
|e| return e.text
|
82
|
+
}
|
83
|
+
end
|
84
|
+
|
85
|
+
def get_longitude(woeid)
|
86
|
+
windxml= get_weather_XML(woeid)
|
87
|
+
windxml.elements.each("rss/channel/item/geo:long"){
|
88
|
+
|e| return e.text
|
89
|
+
}
|
90
|
+
end
|
91
|
+
|
92
|
+
def get_condition(woeid)
|
93
|
+
windxml= get_weather_XML(woeid)
|
94
|
+
windxml.elements.each("rss/channel/item/yweather:condition"){
|
95
|
+
|e| return e.attributes["text"]
|
96
|
+
}
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
metadata
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tell_weather
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rivindu Perera
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-04-08 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: This library provides weather information for a given city
|
14
|
+
email:
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/tell_weather.rb
|
20
|
+
homepage: http://www.rivindu.com/
|
21
|
+
licenses: []
|
22
|
+
metadata: {}
|
23
|
+
post_install_message:
|
24
|
+
rdoc_options: []
|
25
|
+
require_paths:
|
26
|
+
- lib
|
27
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- - '>='
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: '0'
|
32
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - '>='
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
requirements: []
|
38
|
+
rubyforge_project:
|
39
|
+
rubygems_version: 2.0.3
|
40
|
+
signing_key:
|
41
|
+
specification_version: 4
|
42
|
+
summary: Weather inforamtion retrieval
|
43
|
+
test_files: []
|