weather_insight 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c1a90ba47b25ac2d5e9e93f28bb03de16ffecec7
4
+ data.tar.gz: d49aa0dc6919502d6b28e278b1bbdfae77159db4
5
+ SHA512:
6
+ metadata.gz: b61b960d8d1da49a54c2241cc78622ee165edec70afad245d5ee4a33527b2ad74e684d244657432efdf7539ad6757ce65a3cbb0e48b1f533aa4c8c02f425a19f
7
+ data.tar.gz: ab895b2bfa09c3d674a62c797f1485739ab43d02b74653c301408bb746222d787bc344afcf61be73a9a0cb559b52253e10fc6f43b0994f20184da27daf7f6741
data/.bundle/config ADDED
@@ -0,0 +1,3 @@
1
+ ---
2
+ BUNDLE_PATH: vendor/bundle
3
+ BUNDLE_DISABLE_SHARED_GEMS: '1'
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ /vendor/bundle/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in weather_insight.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,36 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ weather_insight (0.0.1)
5
+ nokogiri
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.2.5)
11
+ mini_portile (0.6.2)
12
+ nokogiri (1.6.6.2)
13
+ mini_portile (~> 0.6.0)
14
+ rake (10.4.2)
15
+ rspec (3.2.0)
16
+ rspec-core (~> 3.2.0)
17
+ rspec-expectations (~> 3.2.0)
18
+ rspec-mocks (~> 3.2.0)
19
+ rspec-core (3.2.3)
20
+ rspec-support (~> 3.2.0)
21
+ rspec-expectations (3.2.1)
22
+ diff-lcs (>= 1.2.0, < 2.0)
23
+ rspec-support (~> 3.2.0)
24
+ rspec-mocks (3.2.1)
25
+ diff-lcs (>= 1.2.0, < 2.0)
26
+ rspec-support (~> 3.2.0)
27
+ rspec-support (3.2.2)
28
+
29
+ PLATFORMS
30
+ ruby
31
+
32
+ DEPENDENCIES
33
+ bundler (~> 1.7)
34
+ rake (~> 10.0)
35
+ rspec
36
+ weather_insight!
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 kozakana
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,97 @@
1
+ # WeatherInsight
2
+
3
+ WeatherInsight acquire average data of past weather.
4
+
5
+ ## Notice
6
+
7
+ WeatherInsight is used Web scraping. Therefore be careful about excessive access to a Web server.
8
+ You can adjust time interval which requests to web server.
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'weather_insight'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install weather_insight
25
+
26
+ ## Usage
27
+
28
+ ```ruby
29
+ require 'weather_insight'
30
+ year_data = WeatherInsight.year_data :aichi, interval: 500
31
+
32
+ # How to get 5/28 data.
33
+ year_data[5][28]
34
+ ```
35
+
36
+ ### Parameters
37
+
38
+ 道北 :dohoku
39
+ 道央 :doou
40
+ 道東 :dotou
41
+ 道南 :donan
42
+ 青森 :aomori
43
+ 秋田 :akita
44
+ 岩手 :iwate
45
+ 宮城 :miyagi
46
+ 山形 :yamagata
47
+ 福島 :fukushima
48
+ 茨城 :ibaraki
49
+ 栃木 :tochigi
50
+ 群馬 :gunma
51
+ 埼玉 :saitama
52
+ 東京 :tokyo
53
+ 千葉 :chiba
54
+ 神奈川 :kanagawa
55
+ 長野 :nagano
56
+ 山梨 :yamanashi
57
+ 静岡 :shizuoka
58
+ 愛知 :aichi
59
+ 岐阜 :gifu
60
+ 三重 :mie
61
+ 新潟 :nigata
62
+ 富山 :toyama
63
+ 石川 :ishikawa
64
+ 福井 :fukui
65
+ 滋賀 :shiga
66
+ 京都 :kyoto
67
+ 大阪 :osaka
68
+ 兵庫 :hyogo
69
+ 奈良 :nara
70
+ 和歌山 :wakayama
71
+ 岡山 :okayama
72
+ 広島 :hiroshima
73
+ 島根 :shimane
74
+ 鳥取 :tottori
75
+ 山口 :yamaguchi
76
+ 徳島 :tokushima
77
+ 香川 :kagawa
78
+ 愛媛 :ehime
79
+ 高知 :kochi
80
+ 福岡 :fukuoka
81
+ 大分 :oita
82
+ 長崎 :nagasaki
83
+ 佐賀 :saga
84
+ 熊本 :kumamoto
85
+ 宮崎 :miyazaki
86
+ 鹿児島 :kagoshima
87
+ 沖縄 :okinawa
88
+ 宮古・石垣 :miyako_ishigaki
89
+ 南大東島 :minamidaitojima
90
+
91
+ ## Contributing
92
+
93
+ 1. Fork it ( https://github.com/[my-github-username]/weather_insight/fork )
94
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
95
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
96
+ 4. Push to the branch (`git push origin my-new-feature`)
97
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
@@ -0,0 +1,125 @@
1
+ module UrlList
2
+ STANDARD_URL = 'http://weather.goo.ne.jp/appearance_ratio/'
3
+
4
+ def self.month_url spot, month
5
+ if 1<=month && month<=12
6
+ month = sprintf("%02d",month)
7
+ "#{STANDARD_URL}#{spot_url(spot)}#{month}.html"
8
+ else
9
+ raise ArgumentError, "invalid argument"
10
+ end
11
+ end
12
+
13
+ private
14
+
15
+ def self.spot_url spot
16
+ case spot
17
+ when :dohoku
18
+ 'p0001/'
19
+ when :doou
20
+ 'p0003/'
21
+ when :dotou
22
+ 'p0004/'
23
+ when :donan
24
+ 'p0007/'
25
+ when :aomori
26
+ 'p0008/'
27
+ when :akita
28
+ 'p0009/'
29
+ when :iwate
30
+ 'p0010/'
31
+ when :miyagi
32
+ 'p0011/'
33
+ when :yamagata
34
+ 'p0012/'
35
+ when :fukushima
36
+ 'p0013/'
37
+ when :ibaraki
38
+ 'p0014/'
39
+ when :tochigi
40
+ 'p0015/'
41
+ when :gunma
42
+ 'p0016/'
43
+ when :saitama
44
+ 'p0017/'
45
+ when :tokyo
46
+ 'p0018/'
47
+ when :chiba
48
+ 'p0019/'
49
+ when :kanagawa
50
+ 'p0020/'
51
+ when :nagano
52
+ 'p0021/'
53
+ when :yamanashi
54
+ 'p0022/'
55
+ when :shizuoka
56
+ 'p0023/'
57
+ when :aichi
58
+ 'p0024/'
59
+ when :gifu
60
+ 'p0025/'
61
+ when :mie
62
+ 'p0026/'
63
+ when :nigata
64
+ 'p0027/'
65
+ when :toyama
66
+ 'p0028/'
67
+ when :ishikawa
68
+ 'p0029/'
69
+ when :fukui
70
+ 'p0030/'
71
+ when :shiga
72
+ 'p0031/'
73
+ when :kyoto
74
+ 'p0032/'
75
+ when :osaka
76
+ 'p0033/'
77
+ when :hyogo
78
+ 'p0034/'
79
+ when :nara
80
+ 'p0035/'
81
+ when :wakayama
82
+ 'p0036/'
83
+ when :okayama
84
+ 'p0037/'
85
+ when :hiroshima
86
+ 'p0038/'
87
+ when :shimane
88
+ 'p0039/'
89
+ when :tottori
90
+ 'p0040/'
91
+ when :yamaguchi
92
+ 'p0041/'
93
+ when :tokushima
94
+ 'p0042/'
95
+ when :kagawa
96
+ 'p0043/'
97
+ when :ehime
98
+ 'p0044/'
99
+ when :kochi
100
+ 'p0045/'
101
+ when :fukuoka
102
+ 'p0046/'
103
+ when :oita
104
+ 'p0047/'
105
+ when :nagasaki
106
+ 'p0048/'
107
+ when :saga
108
+ 'p0049/'
109
+ when :kumamoto
110
+ 'p0050/'
111
+ when :miyazaki
112
+ 'p0051/'
113
+ when :kagoshima
114
+ 'p0052/'
115
+ when :okinawa
116
+ 'p0053/'
117
+ when :miyako_ishigaki
118
+ 'p0054/'
119
+ when :minamidaitojima
120
+ 'p0056/'
121
+ else
122
+ raise ArgumentError, "invalid argument"
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,3 @@
1
+ module WeatherInsight
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,95 @@
1
+ # ---
2
+ # Copyright 2015 by kozakana.
3
+ # All rights reserved.
4
+ # See LICENSE.txt for permissions.
5
+ # ---
6
+
7
+ require 'weather_insight/version'
8
+ require 'weather_insight/url_list'
9
+ require 'nokogiri'
10
+ require 'open-uri'
11
+
12
+ module WeatherInsight
13
+ class << self
14
+
15
+ def month_data spot, month
16
+ url = UrlList.month_url spot, month
17
+ get_data url
18
+ end
19
+
20
+ def year_data spot, interval: 300
21
+ year_data = {}
22
+
23
+ 1.upto(12) do |month|
24
+ url = UrlList.month_url spot, month
25
+ month_data = get_data url
26
+ year_data[month] = month_data
27
+ sleep(interval)
28
+ end
29
+
30
+ year_data # year_data[:month][:day]
31
+ end
32
+
33
+ private
34
+
35
+ def get_document url
36
+ charset = nil
37
+ html = open(url) do |f|
38
+ charset = f.charset
39
+ f.read
40
+ end
41
+ Nokogiri::HTML.parse(html, nil, charset)
42
+ end
43
+
44
+ def get_data url
45
+ doc = get_document url
46
+
47
+ info_data = {}
48
+ info = { weather: nil, high: nil, low: nil, average: nil }
49
+ prev_date = nil
50
+ doc.xpath('//tr/td').each do |node|
51
+ date = node.xpath('a').text.to_s
52
+ if date != ""
53
+ md = date.match(/\d+月(\d+)日/)
54
+ date = md[1].to_i
55
+ if prev_date
56
+ info_data[prev_date] = info.dup
57
+ end
58
+ prev_date = date
59
+ end
60
+
61
+ climate = node.xpath('img')
62
+ if climate.length == 1
63
+ weather = climate[0].attribute('alt').value
64
+ info[:weather] = case weather
65
+ when "晴れ"
66
+ :fine
67
+ when "くもり"
68
+ :cloudy
69
+ when "雨"
70
+ :rain
71
+ when "雪"
72
+ :snow
73
+ else
74
+ :other
75
+ end
76
+ end
77
+
78
+ high = node.xpath('span[@class="red"]').text
79
+ low = node.xpath('span[@class="blue"]').text
80
+ temperature = node.text
81
+
82
+ if high != ""
83
+ info[:high] = high[0...-1].to_f
84
+ elsif low != ""
85
+ info[:low] = low[0...-1].to_f
86
+ else
87
+ info[:average] = temperature[0...-1].to_f
88
+ end
89
+ end
90
+
91
+ info_data[prev_date] = info
92
+ info_data
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'weather_insight'
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe WeatherInsight do
4
+ it 'has a version number' do
5
+ expect(WeatherInsight::VERSION).not_to be nil
6
+ end
7
+
8
+ it 'can acquire data of January' do
9
+ month_data = WeatherInsight.month_data :tokyo, 1
10
+ expect(month_data.length).to eq 31
11
+ month_data.each do |day|
12
+ expect(day).not_to be nil
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'weather_insight/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "weather_insight"
8
+ spec.version = WeatherInsight::VERSION
9
+ spec.authors = ["kozakana"]
10
+ spec.email = ["goki727@gmail.com"]
11
+ spec.summary = %q{WeatherInsight acquire average data of past weather.}
12
+ spec.description = %q{WeatherInsight acquire average data of past weather.}
13
+ spec.homepage = "https://github.com/kozakana"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_dependency "nokogiri"
25
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: weather_insight
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - kozakana
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: nokogiri
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: WeatherInsight acquire average data of past weather.
70
+ email:
71
+ - goki727@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".bundle/config"
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".travis.yml"
80
+ - Gemfile
81
+ - Gemfile.lock
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - lib/weather_insight.rb
86
+ - lib/weather_insight/url_list.rb
87
+ - lib/weather_insight/version.rb
88
+ - spec/spec_helper.rb
89
+ - spec/weather_insight_spec.rb
90
+ - weather_insight.gemspec
91
+ homepage: https://github.com/kozakana
92
+ licenses:
93
+ - MIT
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.4.5
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: WeatherInsight acquire average data of past weather.
115
+ test_files:
116
+ - spec/spec_helper.rb
117
+ - spec/weather_insight_spec.rb