weather_today 0.1.1

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
+ SHA256:
3
+ metadata.gz: c4cd02e51ff5051a902c764cb8a0933c956c3fe3988ca4056cd6cdced649fc6c
4
+ data.tar.gz: 7e439a3364a12444dd8384795f2224b7342338db5f7a884f1d4d954d81bc0954
5
+ SHA512:
6
+ metadata.gz: 4ec224b009e25cec76c003567a344d330dfc5bd73059878d1afe2c74e6068db291682cc679b870d576dbfd9136138e54c9707e6b1a516f0df6c806bbcbe3e586
7
+ data.tar.gz: 909cba3aa1bdb481a8163f01fadf38897ec1e465203203c5ec74f65670ea728d7347f5a7717571e80c238efe01d4ed2dfd5c648c436fcf5918d82ee2ac0229d2
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2023-09-26
4
+
5
+ - Initial release
data/README.md ADDED
@@ -0,0 +1,74 @@
1
+ ## WeatherToday
2
+
3
+ This gem provides you with weather information for a specified date. Currently, it is only available for locations within Japan.
4
+
5
+ ## Installation
6
+
7
+ To install this gem on your local machine, add the following line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'weather_today'
11
+ ```
12
+
13
+ Then, execute the following command:
14
+
15
+ ```shell
16
+ bundle install
17
+ ```
18
+
19
+ Alternatively, you can also install the gem using the following command:
20
+
21
+ ```shell
22
+ gem install weather_today-0.1.1.gem
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ The WeatherToday module supplies weather information for your application. You can display the output information using the following script:
28
+
29
+ ```shell
30
+ ruby -Ilib ./exe/exec_weather_today.rb <prefecture>
31
+ ```
32
+
33
+ Reference
34
+
35
+ Example usage:
36
+
37
+ ```shell
38
+ $ ruby -Ilib ./exe/exec_weather_today.rb tokyo
39
+ {"日時"=>["2023-09-27"],
40
+ "天気"=>["曇り"],
41
+ "最高気温"=>[28.3],
42
+ "最低気温"=>[21.5],
43
+ "日の出時刻"=>["2023-09-27T05:32"],
44
+ "日の入り時刻"=>["2023-09-27T17:31"],
45
+ "UV指数"=>[5.9]}
46
+ ```
47
+
48
+ ```shell
49
+ ruby -Ilib ./exe/exec_weather_today.rb okinawa
50
+ {"日時"=>["2023-09-27"],
51
+ "天気"=>["霧雨: 軽い"],
52
+ "最高気温"=>[31.6],
53
+ "最低気温"=>[27.0],
54
+ "日の出時刻"=>["2023-09-27T06:19"],
55
+ "日の入り時刻"=>["2023-09-27T18:21"],
56
+ "UV指数"=>[7.6]}
57
+ ```
58
+
59
+ ```shell
60
+ ruby -Ilib ./exe/exec_weather_today.rb hokkaido
61
+ {"日時"=>["2023-09-27"],
62
+ "天気"=>["曇り"],
63
+ "最高気温"=>[23.9],
64
+ "最低気温"=>[14.3],
65
+ "日の出時刻"=>["2023-09-27T05:26"],
66
+ "日の入り時刻"=>["2023-09-27T17:24"],
67
+ "UV指数"=>[5.05]}
68
+ ```
69
+
70
+ ## License
71
+
72
+ This gem utilizes the "Free Weather API." For further details, please refer to [Open_Meteo](https://open-meteo.com/).
73
+
74
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require 'rubocop/rake_task'
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'weather_today'
5
+
6
+ if ARGV.empty?
7
+ puts 'Usage: weather_wizard <prefecture>'
8
+ exit 1
9
+ end
10
+
11
+ prefecture = ARGV[0]
12
+ client = WeatherToday::WeatherClient.new(prefecture)
13
+ pp client.fetch_weather_data
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LocationData
4
+ DATA = {
5
+ hokkaido: { lat: 43.0646, lon: 141.3468 },
6
+ aomori: { lat: 40.8222, lon: 140.7479 },
7
+ iwate: { lat: 39.5933, lon: 141.3695 },
8
+ miyagi: { lat: 38.2689, lon: 140.8710 },
9
+ akita: { lat: 39.7200, lon: 140.1027 },
10
+ yamagata: { lat: 38.2554, lon: 140.3397 },
11
+ fukushima: { lat: 37.7500, lon: 140.4676 },
12
+ ibaraki: { lat: 36.3416, lon: 140.4468 },
13
+ tochigi: { lat: 36.5652, lon: 139.8836 },
14
+ gunma: { lat: 36.3896, lon: 139.0609 },
15
+ saitama: { lat: 35.9967, lon: 139.3236 },
16
+ chiba: { lat: 35.6073, lon: 140.1066 },
17
+ tokyo: { lat: 35.682839, lon: 139.759455 },
18
+ kanagawa: { lat: 35.4478, lon: 139.6425 },
19
+ niigata: { lat: 37.9162, lon: 139.0363 },
20
+ toyama: { lat: 36.6953, lon: 137.2137 },
21
+ ishikawa: { lat: 36.5943, lon: 136.6256 },
22
+ fukui: { lat: 36.0643, lon: 136.2196 },
23
+ yamanashi: { lat: 35.6916, lon: 138.6850 },
24
+ nagano: { lat: 36.6512, lon: 138.1816 },
25
+ gifu: { lat: 35.7774, lon: 137.0551 },
26
+ shizuoka: { lat: 34.9769, lon: 138.3831 },
27
+ aichi: { lat: 35.1802, lon: 136.9066 },
28
+ mie: { lat: 34.7303, lon: 136.5086 },
29
+ shiga: { lat: 35.2153, lon: 136.1388 },
30
+ kyoto: { lat: 35.0116, lon: 135.7681 },
31
+ osaka: { lat: 34.6937, lon: 135.5023 },
32
+ hyogo: { lat: 34.6913, lon: 135.1830 },
33
+ nara: { lat: 34.6851, lon: 135.8048 },
34
+ wakayama: { lat: 34.2261, lon: 135.1675 },
35
+ tottori: { lat: 35.5037, lon: 134.2377 },
36
+ shimane: { lat: 35.4723, lon: 133.0505 },
37
+ okayama: { lat: 34.6648, lon: 133.9190 },
38
+ hiroshima: { lat: 34.3852, lon: 132.4553 },
39
+ yamaguchi: { lat: 34.1873, lon: 131.4669 },
40
+ tokushima: { lat: 33.9192, lon: 134.2663 },
41
+ kagawa: { lat: 34.3428, lon: 134.0466 },
42
+ ehime: { lat: 33.6219, lon: 132.8206 },
43
+ kochi: { lat: 33.5588, lon: 133.5311 },
44
+ fukuoka: { lat: 33.5903, lon: 130.4017 },
45
+ saga: { lat: 33.2496, lon: 130.2991 },
46
+ nagasaki: { lat: 32.7503, lon: 129.8777 },
47
+ kumamoto: { lat: 32.8030, lon: 130.7079 },
48
+ oita: { lat: 33.2382, lon: 131.6126 },
49
+ miyazaki: { lat: 31.9111, lon: 131.4239 },
50
+ kagoshima: { lat: 31.5667, lon: 130.55 },
51
+ okinawa: { lat: 26.2124, lon: 127.6809 }
52
+ }.freeze
53
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WeatherToday
4
+ VERSION = '0.1.1'
5
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WeatherCodes
4
+ DATA = {
5
+ 0 => '晴天',
6
+ 1 => '晴れ時々曇り',
7
+ 2 => '晴れ時々曇り',
8
+ 3 => '曇り',
9
+ 45 => '霧と降る霧氷',
10
+ 48 => '霧と降る霧氷',
11
+ 51 => '霧雨: 軽い',
12
+ 53 => '霧雨: 中程度',
13
+ 55 => '霧雨: 濃い強度',
14
+ 56 => '氷結霧雨: 軽くて濃い強度',
15
+ 57 => '氷結霧雨: 濃い強度',
16
+ 61 => '雨: 小雨',
17
+ 63 => '雨: 中程度',
18
+ 65 => '雨: 激しい雨',
19
+ 66 => '凍てつく雨: 軽くて激しい雨',
20
+ 67 => '凍てつく雨: 激しい雨',
21
+ 71 => '降雪量: わずか',
22
+ 73 => '降雪量: 中程度',
23
+ 75 => '降雪量: 激しい',
24
+ 77 => '雪の粒',
25
+ 80 => 'にわか雨: 小雨',
26
+ 81 => 'にわか雨: 中程度',
27
+ 82 => 'にわか雨: 激しい',
28
+ 85 => '雪が少し降ったり、激しく降ったりします',
29
+ 86 => '雪が少し降ったり、激しく降ったりします',
30
+ 95 => '雷雨: わずかまたは中程度',
31
+ 96 => '雷雨: わずかまたは激しいひょうを伴う',
32
+ 99 => '雷雨: わずかまたは激しいひょうを伴う'
33
+ }.freeze
34
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'weather_today/version'
4
+ require_relative 'weather_today/location_codes'
5
+ require_relative 'weather_today/weather_codes'
6
+ require 'net/http'
7
+ require 'json'
8
+
9
+ module WeatherToday
10
+ KEY_MAPPINGS = {
11
+ 'time' => '日時',
12
+ 'weathercode' => '天気',
13
+ 'temperature_2m_max' => '最高気温',
14
+ 'temperature_2m_min' => '最低気温',
15
+ 'sunrise' => '日の出時刻',
16
+ 'sunset' => '日の入り時刻',
17
+ 'uv_index_max' => 'UV指数'
18
+ }.freeze
19
+
20
+ class Error < StandardError; end
21
+
22
+ # WeatherClientは指定した都道府県に関する天気データを提供するクラスです。
23
+ # このクラスは、都道府県の緯度と経度を使用して、外部APIから天気情報を取得します。
24
+ class WeatherClient
25
+ def initialize(prefecture)
26
+ @prefecture = prefecture.to_sym
27
+ end
28
+
29
+ def fetch_weather_data
30
+ location_data_entry = LocationData::DATA[@prefecture]
31
+ lat = location_data_entry[:lat]
32
+ lon = location_data_entry[:lon]
33
+ url = "https://api.open-meteo.com/v1/forecast?latitude=#{lat}&longitude=#{lon}&daily=weathercode,temperature_2m_max,temperature_2m_min,sunrise,sunset,uv_index_max&forecast_days=1&timezone=Asia%2FTokyo"
34
+ uri = URI(url)
35
+ response = Net::HTTP.get_response(uri)
36
+
37
+ raise Error, 'Failed to fetch weather data' unless response.is_a?(Net::HTTPSuccess)
38
+
39
+ weather_data = JSON.parse(response.body)
40
+ transform_and_print(weather_data['daily'])
41
+ end
42
+
43
+ private
44
+
45
+ def transform_and_print(daily_data)
46
+ transformed_data = {}
47
+ daily_data.each do |key, value|
48
+ transformed_key = KEY_MAPPINGS[key] || key
49
+ transformed_data[transformed_key] = value
50
+ end
51
+
52
+ transformed_data['天気'] = transformed_data['天気'].map { |code| WeatherCodes::DATA[code] }
53
+ transformed_data
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,4 @@
1
+ module WeatherToday
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/weather_today/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'weather_today'
7
+ spec.version = WeatherToday::VERSION
8
+ spec.authors = ['Jasmine']
9
+ spec.email = ['orange.blossom.1684mk@gmail.com']
10
+
11
+ spec.summary = 'This gem provides you with weather information for a specified date.'
12
+ spec.description = 'Currently, it is only available for locations within Japan.'
13
+ spec.homepage = 'https://github.com/jasmine-tokudome/weather_today/tree/main'
14
+ spec.required_ruby_version = '>= 3.2.0'
15
+
16
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
17
+
18
+ spec.metadata['homepage_uri'] = spec.homepage
19
+ spec.metadata['source_code_uri'] = 'https://github.com/jasmine-tokudome/weather_today/tree/main'
20
+ spec.metadata['changelog_uri'] = 'https://github.com/jasmine-tokudome/weather_today/blob/main/CHANGELOG.md'
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(__dir__) do
25
+ `git ls-files -z`.split("\x0").reject do |f|
26
+ (File.expand_path(f) == __FILE__) ||
27
+ f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor Gemfile])
28
+ end
29
+ end
30
+ spec.bindir = 'exe'
31
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
32
+ spec.require_paths = ['lib']
33
+
34
+ # Uncomment to register a new dependency of your gem
35
+ # spec.add_dependency "example-gem", "~> 1.0"
36
+
37
+ # For more information and examples about making a new gem, check out our
38
+ # guide at: https://bundler.io/guides/creating_gem.html
39
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: weather_today
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Jasmine
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-09-27 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Currently, it is only available for locations within Japan.
14
+ email:
15
+ - orange.blossom.1684mk@gmail.com
16
+ executables:
17
+ - exec_weather_today.rb
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - CHANGELOG.md
22
+ - README.md
23
+ - Rakefile
24
+ - exe/exec_weather_today.rb
25
+ - lib/weather_today.rb
26
+ - lib/weather_today/location_codes.rb
27
+ - lib/weather_today/version.rb
28
+ - lib/weather_today/weather_codes.rb
29
+ - sig/weather_today.rbs
30
+ - weather_today.gemspec
31
+ homepage: https://github.com/jasmine-tokudome/weather_today/tree/main
32
+ licenses: []
33
+ metadata:
34
+ allowed_push_host: https://rubygems.org
35
+ homepage_uri: https://github.com/jasmine-tokudome/weather_today/tree/main
36
+ source_code_uri: https://github.com/jasmine-tokudome/weather_today/tree/main
37
+ changelog_uri: https://github.com/jasmine-tokudome/weather_today/blob/main/CHANGELOG.md
38
+ post_install_message:
39
+ rdoc_options: []
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 3.2.0
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ requirements: []
53
+ rubygems_version: 3.4.19
54
+ signing_key:
55
+ specification_version: 4
56
+ summary: This gem provides you with weather information for a specified date.
57
+ test_files: []