weather_fetcher 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -1
- data/Gemfile.lock +3 -1
- data/VERSION +1 -1
- data/lib/weather_fetcher/fetcher.rb +19 -4
- data/lib/weather_fetcher/providers/provider.rb +12 -11
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71e646fcbe2f0e38d1ac0845dbf009260855bceb
|
4
|
+
data.tar.gz: 1e237fbd785725a0218ddaabcedb33ba0526ef72
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a81ac6441a08b774d665e02f3616d80bff530b9c2114dc56f703841397d006a86749958789e95d8d23dc248c4e1ef780a589dddccbb7963a02a18a0eafa7434
|
7
|
+
data.tar.gz: c5225f3c9ba4f72fdaaedc7a4419d9faf7477a48781d3d9605aa3e7e7efee29741efd8942df20ff2b9b1ae3ad07dade8e092f2e86e2b0fb670da79eb3334949d
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -3,6 +3,7 @@ GEM
|
|
3
3
|
specs:
|
4
4
|
addressable (2.3.6)
|
5
5
|
builder (3.2.2)
|
6
|
+
colorize (0.7.5)
|
6
7
|
curb (0.8.6)
|
7
8
|
descendants_tracker (0.0.4)
|
8
9
|
thread_safe (~> 0.3, >= 0.3.1)
|
@@ -32,7 +33,7 @@ GEM
|
|
32
33
|
rdoc
|
33
34
|
json (1.8.1)
|
34
35
|
jwt (1.2.0)
|
35
|
-
mini_portile (0.6.
|
36
|
+
mini_portile (0.6.2)
|
36
37
|
multi_json (1.10.1)
|
37
38
|
multi_xml (0.5.5)
|
38
39
|
multipart-post (2.0.0)
|
@@ -73,6 +74,7 @@ PLATFORMS
|
|
73
74
|
|
74
75
|
DEPENDENCIES
|
75
76
|
bundler
|
77
|
+
colorize
|
76
78
|
curb
|
77
79
|
jeweler
|
78
80
|
rdoc
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.5
|
@@ -1,22 +1,37 @@
|
|
1
|
+
require 'logger'
|
2
|
+
require 'colorize'
|
3
|
+
|
1
4
|
# Fetcher
|
2
5
|
module WeatherFetcher
|
3
6
|
class Fetcher
|
4
7
|
|
5
|
-
|
8
|
+
attr_accessor :logger
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@logger = Logger.new(STDOUT)
|
12
|
+
end
|
13
|
+
|
14
|
+
def fetch(defs, max_response_time = 0.8)
|
6
15
|
require 'yaml'
|
7
16
|
classes = ProviderList.providers(max_response_time)
|
8
17
|
result = Array.new
|
9
18
|
|
10
19
|
classes.each do |c|
|
11
|
-
|
20
|
+
self.logger.debug("#{self.class.to_s.blue} - starting #{c.to_s.red} with #{defs.size.to_s.green} definitions")
|
21
|
+
|
22
|
+
instance = c.new(defs)
|
23
|
+
instance.logger = self.logger
|
12
24
|
instance.fetch
|
13
|
-
|
25
|
+
class_results = instance.weathers
|
26
|
+
|
27
|
+
self.logger.debug("#{self.class.to_s.blue} - done #{c.to_s.red} with #{class_results.size.to_s.green} results")
|
28
|
+
result += class_results
|
14
29
|
end
|
15
30
|
|
16
31
|
return result
|
17
32
|
end
|
18
33
|
|
19
|
-
def
|
34
|
+
def represent_result(result)
|
20
35
|
puts result.inspect
|
21
36
|
data = result.sort{|r,s| r.time_from <=> s.time_from}
|
22
37
|
data.each do |d|
|
@@ -1,3 +1,6 @@
|
|
1
|
+
require 'logger'
|
2
|
+
require 'colorize'
|
3
|
+
|
1
4
|
# Base class for ordinary weather provider
|
2
5
|
module WeatherFetcher
|
3
6
|
class Provider
|
@@ -10,20 +13,13 @@ module WeatherFetcher
|
|
10
13
|
# Create an instance, definitions can be set here
|
11
14
|
def initialize(_defs = Array.new)
|
12
15
|
@weathers = Array.new
|
16
|
+
@logger = Logger.new(STDOUT)
|
13
17
|
self.defs = _defs
|
14
18
|
end
|
15
19
|
|
16
20
|
attr_reader :weathers
|
17
|
-
|
18
|
-
# Definitions, format like below
|
19
|
-
#- :url: 'http://pogoda.onet.pl/0,846,38,,,inowroclaw,miasto.html'
|
20
|
-
# :city: 'Inowrocław'
|
21
|
-
# :country: 'Poland'
|
22
|
-
# :coord:
|
23
|
-
# :lat: 52.799264
|
24
|
-
# :lon: 18.259935
|
25
|
-
|
26
21
|
attr_reader :defs
|
22
|
+
attr_accessor :logger
|
27
23
|
|
28
24
|
def defs=(_defs)
|
29
25
|
if _defs.kind_of? Hash
|
@@ -47,9 +43,12 @@ module WeatherFetcher
|
|
47
43
|
|
48
44
|
# Fetch everything from definitions (defs)
|
49
45
|
def fetch(ignore_errors: true)
|
46
|
+
self.logger.debug "#{self.class.to_s.blue} - #{defs.size.to_s.green} definitions to process"
|
50
47
|
a = Array.new
|
51
48
|
defs.each do |d|
|
52
49
|
begin
|
50
|
+
self.logger.debug "#{self.class.to_s.blue} - #{d[:name].to_s.yellow}"
|
51
|
+
|
53
52
|
p = fetch_and_process_single(d)
|
54
53
|
p = [] if p.nil?
|
55
54
|
p.each do |pw|
|
@@ -59,11 +58,13 @@ module WeatherFetcher
|
|
59
58
|
|
60
59
|
rescue => e
|
61
60
|
if ignore_errors
|
62
|
-
|
63
|
-
|
61
|
+
self.logger.error "#{self.class.to_s.blue} - #{d.inspect} fail"
|
62
|
+
self.logger.error e.inspect
|
63
|
+
self.logger.error e.backtrace
|
64
64
|
else
|
65
65
|
raise e
|
66
66
|
end
|
67
|
+
|
67
68
|
end
|
68
69
|
a += p unless p.nil?
|
69
70
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: weather_fetcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aleksander Kwiatkowski
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 0.0.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: colorize
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rspec
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|