weather_in_poland 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/Rakefile +2 -0
- data/lib/weather_in_poland.rb +50 -0
- data/lib/weather_in_poland/version.rb +3 -0
- data/weather_in_poland.gemspec +21 -0
- metadata +73 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
module WeatherInPoland
|
2
|
+
|
3
|
+
require "rubygems"
|
4
|
+
require 'mechanize'
|
5
|
+
require 'yahoo-weather'
|
6
|
+
|
7
|
+
attr_reader :city
|
8
|
+
attr_reader :code
|
9
|
+
attr_reader :image
|
10
|
+
attr_reader :thumb
|
11
|
+
|
12
|
+
def self.find_city(name='Gdynia')
|
13
|
+
agent = Mechanize.new
|
14
|
+
page = agent.get("http://weather.yahoo.com/poland/")
|
15
|
+
form = page.form('pform')
|
16
|
+
form.fields.find {|f| f.name == 'location'}.value = name
|
17
|
+
page = agent.submit(form)
|
18
|
+
url = page.uri.to_s
|
19
|
+
near_city = page.parser.xpath('//div[@id="yw-nearstation"]/text()').to_s
|
20
|
+
|
21
|
+
if near_city.empty?
|
22
|
+
return false
|
23
|
+
else
|
24
|
+
@city = near_city.split(':').last.split(',').first.strip
|
25
|
+
@code = url.split('-').last.to_i
|
26
|
+
return true
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.get_weather(code)
|
31
|
+
client = YahooWeather::Client.new
|
32
|
+
response = client.lookup_by_woeid(code, YahooWeather::Units::CELSIUS)
|
33
|
+
return response
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.get_image(dane)
|
37
|
+
sun_rise = dane.astronomy.sunrise
|
38
|
+
sun_set = dane.astronomy.sunset
|
39
|
+
|
40
|
+
if sun_rise.past? && sun_set.future?
|
41
|
+
time_of_day = 'd';
|
42
|
+
else
|
43
|
+
time_of_day = 'n';
|
44
|
+
end
|
45
|
+
|
46
|
+
@thumb = "http://l.yimg.com/a/i/us/nws/weather/gr/#{dane.condition.code.to_s+time_of_day}s.png"
|
47
|
+
@image = "http://l.yimg.com/a/i/us/nws/weather/gr/#{dane.condition.code.to_s+time_of_day}.png"
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "weather_in_poland/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "weather_in_poland"
|
7
|
+
s.version = WeatherInPoland::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Oskar Szrajer"]
|
10
|
+
s.email = ["oskarszrajer@gmail.com"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{Weather in Poland checker}
|
13
|
+
s.description = %q{Simply gem for Yahoo! Weather with location checking to get proper location code}
|
14
|
+
|
15
|
+
s.rubyforge_project = "weather_in_poland"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: weather_in_poland
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Oskar Szrajer
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-02-09 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: Simply gem for Yahoo! Weather with location checking to get proper location code
|
23
|
+
email:
|
24
|
+
- oskarszrajer@gmail.com
|
25
|
+
executables: []
|
26
|
+
|
27
|
+
extensions: []
|
28
|
+
|
29
|
+
extra_rdoc_files: []
|
30
|
+
|
31
|
+
files:
|
32
|
+
- .gitignore
|
33
|
+
- Gemfile
|
34
|
+
- Rakefile
|
35
|
+
- lib/weather_in_poland.rb
|
36
|
+
- lib/weather_in_poland/version.rb
|
37
|
+
- weather_in_poland.gemspec
|
38
|
+
has_rdoc: true
|
39
|
+
homepage: ""
|
40
|
+
licenses: []
|
41
|
+
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
44
|
+
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
none: false
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
hash: 3
|
53
|
+
segments:
|
54
|
+
- 0
|
55
|
+
version: "0"
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
hash: 3
|
62
|
+
segments:
|
63
|
+
- 0
|
64
|
+
version: "0"
|
65
|
+
requirements: []
|
66
|
+
|
67
|
+
rubyforge_project: weather_in_poland
|
68
|
+
rubygems_version: 1.3.7
|
69
|
+
signing_key:
|
70
|
+
specification_version: 3
|
71
|
+
summary: Weather in Poland checker
|
72
|
+
test_files: []
|
73
|
+
|