meteo_pl 1.0.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b70f92ea15424c0fb9e779c29b265148040602a4
4
+ data.tar.gz: 8c72d0c65ba2a0015a9fb696d26850980f5ee645
5
+ SHA512:
6
+ metadata.gz: 6e938cc302c5d01ba14f9d2b20f6aba22aef12d3944c36dd47132f4acee26d8d46d5424fb46a4e39728a95c419d10313c371b17ffecaa7dbaf4b91701bc8aa56
7
+ data.tar.gz: b308e84536c896b20d8bf88b965cca8c63a62c01c2b0e8dc1af4c226a5e6af0cb83615552ea176316ab710429abe3e4d06178e762006eba3f9f3329500bd0edc
data/lib/meteo_pl.rb CHANGED
@@ -1,255 +1,8 @@
1
- # encoding: utf-8
2
-
3
- require 'capybara'
4
- require 'capybara/dsl'
5
- require 'capybara-webkit'
6
- require 'open-uri'
7
- require 'mini_magick'
8
- require 'launchy'
9
-
10
- module Meteo_pl
11
- GRAPH_TYPES = {
12
- :um => {
13
- :dimensions => {:width => 480, :height => 225, :off_width => 0, :off_height => 0},
14
- },
15
- :coamps => {
16
- :dimensions => {:width => 598, :height => 225, :off_width => 0, :off_height => 0},
17
- }
18
- }
19
-
20
- class Fetcher
21
- include Capybara::DSL
22
- attr_accessor :graph
23
-
24
- HOST = 'http://www.meteo.pl/'
25
-
26
- OTHER_LOC_TXT = 'Wybierz inną miejscowość'
27
- SEARCH_BUTTON_TXT = 'Szukaj'
28
-
29
- def initialize
30
- #Capybara basic configuration
31
- Capybara.run_server = false
32
- Capybara.current_driver = :webkit
33
- Capybara.app_host = HOST
34
- end
35
-
36
- def graph=(value)
37
- raise ArgumentError, "graph should respond to location" if !value.respond_to? :location
38
- raise ArgumentError, "graph should respond to type" if !value.respond_to? :type
39
- raise ArgumentError, "Argument not supported, expected #{GRAPH_TYPES.keys.to_s} got #{value.type}" if !GRAPH_TYPES.keys.include? value.type
40
- @graph = value
41
- end
42
-
43
- def get_diagram
44
- raise RuntimeError, "no graph assigned" if graph.nil?
45
-
46
- tab = "#tab_#{graph.type}"
47
- tries = 0
48
-
49
- begin
50
- visit('/')
51
- find(tab).click
52
- find('a', :text => OTHER_LOC_TXT).click
53
- win_count = page.driver.browser.window_handles.length
54
- raise RuntimeError, "Wrong number of open windows" if win_count != 2
55
- within_window page.driver.browser.window_handles.last do
56
- find(:xpath, "//input[@name='name']").set(graph.location)
57
- find(:xpath, "//input[@type='submit' and @value='#{SEARCH_BUTTON_TXT}']").click
58
- link = first(:css, 'table a')
59
- raise RuntimeError, "No data for '#{graph.location}' location found" if link.nil? or !(link.text =~ Regexp.new(graph.location))
60
- link.click
61
- end
62
- rescue RuntimeError => e
63
- puts e.message
64
- tries += 1
65
- retry if tries < 5
66
- end
67
-
68
- begin
69
- within_window page.driver.browser.window_handles.last do
70
- img = first('img#meteorogram')
71
- raise RuntimeError, "No image src for chosen meteorogram found" if img.nil?
72
- return StringIO.new(open(img[:src]) { |f| f.read })
73
- end
74
- rescue Exception => e
75
- raise RuntimeError, "Error during partial image buffer preparation: #{e.message}"
76
- ensure
77
- page.reset!
78
- end
79
- end
80
- end
81
-
82
- class Graph
83
- attr_reader :location, :type, :img_data, :dimensions
84
- attr_accessor :fetcher
85
-
86
- def initialize(location, type, options = nil)
87
- raise ArgumentError, "Argument not supported, expected #{GRAPH_TYPES.keys.to_s} got #{type}" if !GRAPH_TYPES.keys.include? type
88
- @location = location
89
- @type = type ? type : nil
90
- @img_data = options && options[:img_data] ? options[:img_data] : nil
91
-
92
- @dimensions = options && options[:dimensions] ? options[:dimensions] : GRAPH_TYPES[type][:dimensions]
93
-
94
- self.fetcher = options[:fetcher] if options && options[:fetcher]
95
- end
96
-
97
- def fetcher=(value)
98
- raise ArgumentError, "Fetcher should respond to graph" if !value.respond_to? :graph
99
- raise ArgumentError, "Fetcher should respond to get_diagram" if !value.respond_to? :get_diagram
100
- @fetcher = value
101
- end
102
-
103
- def to_s
104
- "#{location} - #{type}"
105
- end
106
-
107
- def fetch_data
108
- raise RuntimeError, "no fetcher assigned" if fetcher.nil?
109
- fetcher.graph = self
110
- self.img_data = fetcher.get_diagram
111
- end
112
-
113
- def process_data
114
- raise RuntimeError, "No StringIO data to read" if img_data.nil?
115
- begin
116
- image = MiniMagick::Image.read(img_data)
117
- rescue Exception => e
118
- puts "Some problems with Minimagick and buffers: #{e.message}"
119
- end
120
-
121
- crop = "#{dimensions[:width]}x#{dimensions[:height]}+#{dimensions[:off_width]}+#{dimensions[:off_height]}"
122
-
123
- #TODO: check Regexp match against crop pattern
124
- # raise RuntimeError if !Regexp.new
125
- image.crop crop
126
- self.img_data = image
127
- end
128
-
129
- def img_data=(value)
130
- @img_data = value
131
- end
132
-
133
- def eql?(o)
134
- self.hash == o.hash
135
- end
136
-
137
- def hash
138
- code = 17
139
- code = 37*code + @location.hash
140
- code
141
- end
142
-
143
- end
144
-
145
- #performs desired operation
146
- class Generate
147
- class << self
148
- def go(*graphs)
149
- processed_graphs = process_graphs(graphs)
150
- organized_graphs = organize_graphs(processed_graphs)
151
- merged_image = merge_graphs(organized_graphs)
152
- view merged_image
153
- rescue Exception => e
154
- puts e.message
155
- end
156
-
157
- def go_by_names(*names)
158
- graphs = Array.new
159
- names.each do |name|
160
- graphs << Graph.new(name, :coamps)
161
- graphs << Graph.new(name, :um)
162
- end
163
- go(*graphs)
164
- end
165
-
166
- private
167
-
168
- def view(image)
169
- begin
170
- img_file = File.new Dir::tmpdir + '/' + Dir::Tmpname.make_tmpname(['pogoda', '.png'], nil), 'w'
171
- image.write img_file.path
172
- Launchy.open img_file.path
173
- ensure
174
- img_file.close
175
- end
176
- end
177
-
178
- #merging labeled images into one file
179
- def merge_graphs(graphs)
180
- locations = Array.new
181
- graphs.each do |key, value|
182
- # combine subsets
183
- combined_graphs = combine_graphs(value.reverse)
184
- # add labels
185
- labeled_image = text_write combined_graphs, key.location
186
- locations << Graph.new(key.location, key.type, {img_data: labeled_image, dimensions: {:width => labeled_image[:width], :height => labeled_image[:height], :off_width => 0, :off_height => 0}})
187
- end
188
- combine_graphs locations
189
- end
190
-
191
- def text_write(img, text)
192
- img.combine_options do |c|
193
- c.background '#e2e2e2'
194
- c.gravity "South"
195
- c.extent "#{img[:width]}x#{img[:height]+25}"
196
- end
197
-
198
- img.combine_options do |c|
199
- c.font File.dirname(__FILE__) + "/FreeMonoBold.ttf"
200
- c.pointsize 25
201
- c.draw "fill red text 2,20 '#{text}'"
202
- end
203
- img
204
- end
205
-
206
- def combine_graphs(graphs, img = nil)
207
- return img if graphs.count.zero? || graphs.nil?
208
- img = graphs.pop.img_data if img.nil?
209
-
210
- if (!graphs.empty?)
211
- graph = graphs.pop
212
- img.combine_options do |c|
213
- c.background '#e2e2e2'
214
- c.extent "#{img['width'] > graph.dimensions[:width] ? img['width'] : graph.dimensions[:width]}x#{img['height']+graph.dimensions[:height]}"
215
- end
216
- img = img.composite(graph.img_data) do |c|
217
- c.compose "Over"
218
- c.gravity "SouthWest"
219
- end
220
- end
221
- combine_graphs(graphs, img)
222
- end
223
-
224
- def organize_graphs(graphs)
225
- organized_graphs = Hash.new
226
- graphs.each do |g|
227
- organize_graph organized_graphs, g
228
- end
229
- organized_graphs
230
- end
231
-
232
- def organize_graph(og, g)
233
- if (!og.has_key? g)
234
- og[g] = [g]
235
- else
236
- og[g] << g
237
- end
238
- end
239
-
240
- def process_graphs(graphs)
241
- fetcher = Meteo_pl::Fetcher.new
242
- graphs.map do |g|
243
- process_graph g, fetcher
244
- end
245
- end
246
-
247
- def process_graph(graph, fetcher)
248
- graph.fetcher = fetcher
249
- graph.fetch_data
250
- graph.process_data
251
- graph
252
- end
253
- end
254
- end
255
- end
1
+ #!/usr/bin/env ruby
2
+ require 'meteo_pl/io/file_handler'
3
+ require 'meteo_pl/io/image_opener'
4
+ require 'meteo_pl/net/http'
5
+ require 'meteo_pl/utility/command'
6
+ require 'meteo_pl/utility/graph'
7
+ require 'meteo_pl/utility/presenter'
8
+ require 'meteo_pl/utility/forecast'
metadata CHANGED
@@ -1,205 +1,59 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: meteo_pl
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
5
- prerelease:
4
+ version: 2.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Marcin Kot
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-01-08 00:00:00.000000000 Z
11
+ date: 2017-12-06 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
- name: capybara
14
+ name: rspec
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
- version: 2.1.0
22
- type: :runtime
23
- prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ~>
28
- - !ruby/object:Gem::Version
29
- version: 2.1.0
30
- - !ruby/object:Gem::Dependency
31
- name: capybara-webkit
32
- requirement: !ruby/object:Gem::Requirement
33
- none: false
34
- requirements:
35
- - - ~>
36
- - !ruby/object:Gem::Version
37
- version: 1.1.0
38
- type: :runtime
39
- prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ~>
44
- - !ruby/object:Gem::Version
45
- version: 1.1.0
46
- - !ruby/object:Gem::Dependency
47
- name: mini_magick
48
- requirement: !ruby/object:Gem::Requirement
49
- none: false
50
- requirements:
51
- - - ~>
52
- - !ruby/object:Gem::Version
53
- version: 3.7.0
54
- type: :runtime
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - ~>
60
- - !ruby/object:Gem::Version
61
- version: 3.7.0
62
- - !ruby/object:Gem::Dependency
63
- name: launchy
64
- requirement: !ruby/object:Gem::Requirement
65
- none: false
66
- requirements:
67
- - - ! '>='
68
- - !ruby/object:Gem::Version
69
- version: '0'
70
- type: :runtime
71
- prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - ! '>='
76
- - !ruby/object:Gem::Version
77
- version: '0'
78
- - !ruby/object:Gem::Dependency
79
- name: minitest
80
- requirement: !ruby/object:Gem::Requirement
81
- none: false
82
- requirements:
83
- - - ! '>='
84
- - !ruby/object:Gem::Version
85
- version: '0'
86
- type: :development
87
- prerelease: false
88
- version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
- requirements:
91
- - - ! '>='
92
- - !ruby/object:Gem::Version
93
- version: '0'
94
- - !ruby/object:Gem::Dependency
95
- name: rdoc
96
- requirement: !ruby/object:Gem::Requirement
97
- none: false
98
- requirements:
99
- - - ~>
100
- - !ruby/object:Gem::Version
101
- version: '3.12'
102
- type: :development
103
- prerelease: false
104
- version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
- requirements:
107
- - - ~>
108
- - !ruby/object:Gem::Version
109
- version: '3.12'
110
- - !ruby/object:Gem::Dependency
111
- name: bundler
112
- requirement: !ruby/object:Gem::Requirement
113
- none: false
114
- requirements:
115
- - - ~>
116
- - !ruby/object:Gem::Version
117
- version: '1.0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
- requirements:
123
- - - ~>
124
- - !ruby/object:Gem::Version
125
- version: '1.0'
126
- - !ruby/object:Gem::Dependency
127
- name: jeweler
128
- requirement: !ruby/object:Gem::Requirement
129
- none: false
130
- requirements:
131
- - - ~>
132
- - !ruby/object:Gem::Version
133
- version: 2.0.0
134
- type: :development
135
- prerelease: false
136
- version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
- requirements:
139
- - - ~>
140
- - !ruby/object:Gem::Version
141
- version: 2.0.0
142
- - !ruby/object:Gem::Dependency
143
- name: simplecov
144
- requirement: !ruby/object:Gem::Requirement
145
- none: false
146
- requirements:
147
- - - ! '>='
148
- - !ruby/object:Gem::Version
149
- version: '0'
19
+ version: '3.6'
150
20
  type: :development
151
21
  prerelease: false
152
22
  version_requirements: !ruby/object:Gem::Requirement
153
- none: false
154
23
  requirements:
155
- - - ! '>='
24
+ - - "~>"
156
25
  - !ruby/object:Gem::Version
157
- version: '0'
26
+ version: '3.6'
158
27
  description: Fetches and manipulates on weather forecast graphs from http://www.meteo.pl
159
28
  service
160
29
  email: marcin@kotu.pl
161
30
  executables: []
162
31
  extensions: []
163
- extra_rdoc_files:
164
- - LICENSE.txt
165
- - README.rdoc
32
+ extra_rdoc_files: []
166
33
  files:
167
- - .document
168
- - Gemfile
169
- - LICENSE.txt
170
- - README.rdoc
171
- - Rakefile
172
- - VERSION
173
- - lib/FreeMonoBold.ttf
174
34
  - lib/meteo_pl.rb
175
- - test/helper.rb
176
- - test/test_meteo_pl.rb
177
35
  homepage: http://github.com/kotu-pl/meteo_pl
178
36
  licenses:
179
37
  - MIT
38
+ metadata: {}
180
39
  post_install_message:
181
40
  rdoc_options: []
182
41
  require_paths:
183
42
  - lib
184
43
  required_ruby_version: !ruby/object:Gem::Requirement
185
- none: false
186
44
  requirements:
187
- - - ! '>='
45
+ - - ">="
188
46
  - !ruby/object:Gem::Version
189
47
  version: '0'
190
- segments:
191
- - 0
192
- hash: 2206110096137027161
193
48
  required_rubygems_version: !ruby/object:Gem::Requirement
194
- none: false
195
49
  requirements:
196
- - - ! '>='
50
+ - - ">="
197
51
  - !ruby/object:Gem::Version
198
52
  version: '0'
199
53
  requirements: []
200
54
  rubyforge_project:
201
- rubygems_version: 1.8.25
55
+ rubygems_version: 2.6.11
202
56
  signing_key:
203
- specification_version: 3
57
+ specification_version: 4
204
58
  summary: Weather forecast from http://www.meteo.pl
205
59
  test_files: []
data/.document DELETED
@@ -1,5 +0,0 @@
1
- lib/**/*.rb
2
- bin/*
3
- -
4
- features/**/*.feature
5
- LICENSE.txt
data/Gemfile DELETED
@@ -1,17 +0,0 @@
1
- source "http://rubygems.org"
2
-
3
- # Add dependencies required to use your gem here.
4
- gem 'capybara', "~> 2.1.0"
5
- gem 'capybara-webkit', "~> 1.1.0"
6
- gem 'mini_magick', "~> 3.7.0"
7
- gem 'launchy', ">= 0"
8
-
9
- # Add dependencies to develop your gem here.
10
- # Include everything needed to run rake, tests, features, etc.
11
- group :development do
12
- gem "minitest", ">= 0"
13
- gem "rdoc", "~> 3.12"
14
- gem "bundler", "~> 1.0"
15
- gem "jeweler", "~> 2.0.0"
16
- gem "simplecov", ">= 0"
17
- end
data/LICENSE.txt DELETED
@@ -1,20 +0,0 @@
1
- Copyright (c) 2014 Marcin Kot
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc DELETED
@@ -1,46 +0,0 @@
1
- = meteo_pl
2
-
3
- This gem fetches and manipulates on weather forecast graphs from http://www.meteo.pl service.
4
- It allows to fetch coamps and um diagrams separately if necessery and joins them with location label.
5
- By it uses Launchy to open combined graph in your default image viewer.
6
-
7
- == example usage
8
-
9
- ``` ruby
10
-
11
- require 'meteo_pl'
12
- include Meteo_pl
13
-
14
- # choose graph types manually
15
- Generate.go(Graph.new('Warszawa', :coamps), Graph.new('Kraków', :um), Graph.new('Zakopane', :um))
16
- # call graphs by location name only, both types um/comps will be fetched, joined together and labeled
17
- Generate.go_by_names("Kraków", "Gdańsk", "Warszawa", "Sandomierz", "Lublin")
18
-
19
- ```
20
-
21
- == Installation dependencies
22
-
23
- * QT (thru capybara webkit): https://github.com/thoughtbot/capybara-webkit/wiki/Installing-Qt-and-compiling-capybara-webkit
24
- * Imagemagick: http://www.imagemagick.org
25
-
26
- == Versions
27
-
28
- * 1.0.0 converted to gem, option to choose um/coamps diagrams separetely and merge multiple diagrams with location labeling
29
- * 0.2.0 Custom city selection, code reorganization
30
- * 0.1.0 Initial version, fetches diagrams for Warsaw only. Tested on Ubuntu 12.04 LTS.
31
-
32
- == Contributing to meteo_pl
33
-
34
- * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
35
- * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
36
- * Fork the project.
37
- * Start a feature/bugfix branch.
38
- * Commit and push until you are happy with your contribution.
39
- * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
40
- * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
41
-
42
- == Copyright
43
-
44
- Copyright (c) 2014 Marcin Kot. See LICENSE.txt for
45
- further details.
46
-
data/Rakefile DELETED
@@ -1,45 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'rubygems'
4
- require 'bundler'
5
- begin
6
- Bundler.setup(:default, :development)
7
- rescue Bundler::BundlerError => e
8
- $stderr.puts e.message
9
- $stderr.puts "Run `bundle install` to install missing gems"
10
- exit e.status_code
11
- end
12
- require 'rake'
13
-
14
- require 'jeweler'
15
- Jeweler::Tasks.new do |gem|
16
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
- gem.name = "meteo_pl"
18
- gem.homepage = "http://github.com/kotu-pl/meteo_pl"
19
- gem.license = "MIT"
20
- gem.summary = %Q{Weather forecast from http://www.meteo.pl}
21
- gem.description = %Q{Fetches and manipulates on weather forecast graphs from http://www.meteo.pl service}
22
- gem.email = "marcin@kotu.pl"
23
- gem.authors = ["Marcin Kot"]
24
- # dependencies defined in Gemfile
25
- end
26
- Jeweler::RubygemsDotOrgTasks.new
27
-
28
- require 'rake/testtask'
29
- Rake::TestTask.new(:test) do |test|
30
- test.libs << 'lib' << 'test'
31
- test.pattern = 'test/**/test_*.rb'
32
- test.verbose = true
33
- end
34
-
35
- task :default => :test
36
-
37
- require 'rdoc/task'
38
- Rake::RDocTask.new do |rdoc|
39
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
40
-
41
- rdoc.rdoc_dir = 'rdoc'
42
- rdoc.title = "meteo_pl #{version}"
43
- rdoc.rdoc_files.include('README*')
44
- rdoc.rdoc_files.include('lib/**/*.rb')
45
- end
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 1.0.0
data/lib/FreeMonoBold.ttf DELETED
Binary file
data/test/helper.rb DELETED
@@ -1,19 +0,0 @@
1
- require 'rubygems'
2
- require 'bundler'
3
- begin
4
- Bundler.setup(:default, :development)
5
- rescue Bundler::BundlerError => e
6
- $stderr.puts e.message
7
- $stderr.puts "Run `bundle install` to install missing gems"
8
- exit e.status_code
9
- end
10
- require 'minitest/unit'
11
-
12
- $LOAD_PATH.unshift(File.dirname(__FILE__))
13
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
- require 'meteo_pl'
15
-
16
- class MiniTest::Unit::TestCase
17
- end
18
-
19
- MiniTest::Unit.autorun
@@ -1,7 +0,0 @@
1
- require 'helper'
2
-
3
- class TestMeteoPl < MiniTest::Unit::TestCase
4
- def test_something_for_real
5
- flunk "hey buddy, you should probably rename this file and start testing for real"
6
- end
7
- end