weather-forecast 0.0.0

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
+ SHA256:
3
+ metadata.gz: 27876f859e30cfb06a997a0e7aa1a13a72a522b87e6a735ed3b28e1a2cb54821
4
+ data.tar.gz: c419a3e455141ce5be4f26a139dee8207afbf1d7c507142598f8c84650c2667d
5
+ SHA512:
6
+ metadata.gz: 849a23a721fee16d8f235d3f956cbbaf7796ac8a49e91ab5bf9ee4812894ccf6a94c06dc7c437912a6304b2bb5316e9d9388f46a1f10429a43731287649b4077
7
+ data.tar.gz: 0d9b13988c203e297d013608855bb2ae7cf21722ecb5b8f775441f643c1a5f3dad30e2a15118c3b318ad8a3da4ea1736cf9a18a5ba1a1fef9fe57cab9c511b8b
data/bin/execute ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/weather_forecast'
4
+
5
+ Weather::ForecastCli.new.start
data/lib/emoji.rb ADDED
@@ -0,0 +1,35 @@
1
+ class String
2
+ def to_emoji
3
+ case self
4
+ when 'thunderstorm'
5
+ "\u{26A1}"
6
+ when 'light rain'
7
+ "\u{1F326}"
8
+ when 'rain'
9
+ "\u{2614}"
10
+ when 'clear sky'
11
+ "\u{1F31E}"
12
+ when 'few clouds'
13
+ "\u{26C5}"
14
+ when 'scattered clouds'
15
+ "\u{1F324}"
16
+ when 'broken clouds'
17
+ "\u{1F325}"
18
+ when 'overcast clouds'
19
+ "\u{2601}"
20
+ when 'tornado'
21
+ "\u{1F32A}"
22
+ when 'cold'
23
+ "\u{2744}"
24
+ when 'hot'
25
+ "\u{1F525}"
26
+ when 'windy'
27
+ "\u{1F32C}"
28
+ when 'hail'
29
+ "\u{1F30A}"
30
+ else
31
+ "\u{1F30A}" # error
32
+ end
33
+ end
34
+
35
+ end
@@ -0,0 +1,16 @@
1
+ require "bundler/setup"
2
+ Bundler.require
3
+
4
+ require 'dotenv'
5
+ Dotenv.load
6
+ require 'tty-prompt'
7
+ require 'httparty'
8
+ require 'json'
9
+ require 'terminal-table'
10
+ require 'colorize'
11
+ require 'ruby_figlet'
12
+ require 'forecast/version'
13
+ require 'forecastapi.rb'
14
+ require 'forecastcli.rb'
15
+ require 'forecast.rb'
16
+ require 'emoji.rb'
data/lib/forecast.rb ADDED
@@ -0,0 +1,53 @@
1
+ require 'pry'
2
+
3
+ module Weather
4
+
5
+ class Forecast
6
+ @@all = []
7
+ attr_accessor :location, :date, :temp, :humidity, :description
8
+
9
+ def initialize (date:, temp:, humidity:, description:)
10
+ @date = date
11
+ @temp = temp
12
+ @humidity = humidity
13
+ @description = description
14
+ save
15
+ end
16
+
17
+ def save
18
+ @@all << self
19
+ end
20
+
21
+ def self.day_display
22
+ forecast = []
23
+
24
+ 8.times do
25
+ forecast << @@all.shift
26
+ end
27
+
28
+ forecast.each do |data|
29
+ puts Terminal::Table.new(
30
+ rows: [
31
+ [data.date, "Temp: #{data.temp} F Humidity: #{data.humidity} Sky: #{data.description.to_emoji} #{data.description}"]
32
+ ],
33
+ style: {
34
+ border_i: 'X',
35
+ border_x: '=',
36
+ width: 130
37
+ }
38
+ )
39
+ end
40
+
41
+ end
42
+
43
+
44
+ def self.all
45
+ @@all
46
+ end
47
+
48
+ def self.erase
49
+ @@all.clear
50
+ end
51
+ end
52
+
53
+ end
@@ -0,0 +1,5 @@
1
+ module Weather
2
+
3
+ VERSION = "0.0.0"
4
+
5
+ end
@@ -0,0 +1,29 @@
1
+ require 'pry'
2
+
3
+ module Weather
4
+ class ForecastApi
5
+ APP_ID = ENV['API_KEY']
6
+
7
+ # fetch forecast info from OpenWeather API
8
+ def self.fetch(zipcode)
9
+ url = "http://api.openweathermap.org/data/2.5/forecast?zip=#{zipcode}&units=imperial&appid=#{APP_ID}"
10
+
11
+ response = HTTParty.get(url)
12
+ query = JSON.parse(response.body, symbolize_names: true)
13
+ query[:list].each do |data|
14
+ Weather::Forecast.new(
15
+ date: Time.at(data[:dt]).strftime('%a %b-%d %H:%M'),
16
+ temp: data[:main][:temp],
17
+ humidity: data[:main][:humidity],
18
+ description: data[:weather].first[:description]
19
+ )
20
+ end
21
+
22
+ Weather::Forecast.all.each {|forecast| forecast.location = query[:city][:name]}
23
+
24
+ end
25
+
26
+ end
27
+
28
+
29
+ end
@@ -0,0 +1,146 @@
1
+ module Weather
2
+ class ForecastCli
3
+ include RubyFiglet
4
+ APP_ID = ENV['API_KEY']
5
+ $prompt = TTY::Prompt.new
6
+ def start
7
+ self.welcome
8
+ self.instructions
9
+ end
10
+
11
+ def welcome
12
+
13
+ puts Figlet.new('WEATHER-FORECAST').to_s.colorize(:red)
14
+ puts ''
15
+ puts ''
16
+ puts 'Welcome to your forecast!'.colorize(:blue)
17
+ puts ''
18
+ puts 'This is your personalized weather assistant that allows you
19
+ to get daily weather information by zipcode.'
20
+ line_break
21
+ puts ''
22
+ puts 'Instructions'.colorize(:red)
23
+ puts ''
24
+ puts 'Follow instruction bellow'
25
+ puts 'Enter zipcode to get weather detail'
26
+ puts "Type 'exit' to quit".colorize(:blue)
27
+ self.line_break
28
+ puts ''
29
+ end
30
+
31
+ def instructions
32
+ puts 'Enter your five digit zipcode to get started or "exit" to quit:'.colorize(:blue)
33
+ zipcode = gets.chomp.downcase
34
+ #check for vald zip code: all digits string and length = 5
35
+ while zipcode != 'exit'
36
+ if zipcode[/[0-9]+/] == zipcode && zipcode.length == 5
37
+ system('cls') || system('clear')
38
+ Weather::ForecastApi.fetch(zipcode)
39
+ puts "This is the 24 HRS forecast for #{Weather::Forecast.all.first.location}:".colorize(:blue)
40
+ puts ''
41
+ Weather::Forecast.day_display
42
+ line_break
43
+ puts ''
44
+ @options = %w(Exit Check-Another-Area Next-Day-Forecast Next-2-Days-Forecast Next-3-Days-Forecast Next-4-Days-Forecast)
45
+ additional_options
46
+ else
47
+ begin
48
+ raise Error
49
+ rescue Error => exception
50
+ puts exception.message
51
+ end
52
+ instructions
53
+ end
54
+ end
55
+ system('cls') || system('clear')
56
+ goodbye
57
+ end
58
+
59
+ def additional_options
60
+ menu
61
+ system('cls') || system('clear')
62
+ case @selection
63
+ when 'Next-Day-Forecast'
64
+ @@counter = 1
65
+ specific_request
66
+ additional_options
67
+
68
+ when 'Next-2-Days-Forecast'
69
+ @@counter = 2
70
+ specific_request
71
+ additional_options
72
+ when 'Next-3-Days-Forecast'
73
+ @@counter = 3
74
+ specific_request
75
+ additional_options
76
+ when 'Next-4-Days-Forecast'
77
+ @@counter = 4
78
+ specific_request
79
+ additional_options
80
+ when 'Check-Another-Area'
81
+ Weather::Forecast.erase
82
+ system('cls') || system('clear')
83
+ instructions
84
+
85
+ else
86
+ Weather::Forecast.erase
87
+ system('cls') || system('clear')
88
+ goodbye
89
+ exit
90
+ end
91
+
92
+ end
93
+
94
+ def menu
95
+ @selection = $prompt.select("What would you like to do next?".colorize(:green), @options)
96
+ end
97
+
98
+ def line_break
99
+ puts '============================================================================================================='.colorize(:white)
100
+ end
101
+
102
+ def goodbye
103
+ puts 'Thanks "for" visiting!'.colorize(:blue)
104
+ puts 'Enjoy the weather until next time :)'.colorize(:blue)
105
+ end
106
+
107
+ def specific_request
108
+ if Weather::Forecast.all.empty?
109
+ begin
110
+ raise WeatherError
111
+ rescue WeatherError => exception
112
+ puts exception.message
113
+ end
114
+ @options = %w(Exit Check-Another-Area)
115
+ additional_options
116
+ else
117
+ @@counter.times do
118
+ Weather::Forecast.day_display unless Weather::Forecast.all.empty?
119
+ @options.pop
120
+ end
121
+
122
+ puts 'You have now viewed the maximum five days forecast.'.colorize(:red) if @options.size == 2
123
+ end
124
+ line_break
125
+ end
126
+
127
+ class Error < StandardError
128
+ def message
129
+ puts 'Invalid Input'.colorize(:red)
130
+ puts ''
131
+ puts 'Please try again!'.colorize(:green)
132
+ end
133
+ end
134
+
135
+ class WeatherError < StandardError
136
+ def message
137
+ puts 'No more Forecast available'.colorize(:red)
138
+ puts ''
139
+ puts 'Make another Selection!'.colorize(:green)
140
+ end
141
+ end
142
+
143
+ end
144
+
145
+
146
+ end
@@ -0,0 +1,4 @@
1
+ module Weather
2
+
3
+ end
4
+ require_relative './environment'
metadata ADDED
@@ -0,0 +1,224 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: weather-forecast
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Vanessa Fotso
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-12-28 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.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '13.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '13.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: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: dotenv
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: colorize
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: tty
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: tty-prompt
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: httparty
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: json
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: terminal-table
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: ruby_figlet
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ description:
182
+ email: vanessuniq@gmail.com
183
+ executables:
184
+ - execute
185
+ extensions: []
186
+ extra_rdoc_files: []
187
+ files:
188
+ - bin/execute
189
+ - lib/emoji.rb
190
+ - lib/environment.rb
191
+ - lib/forecast.rb
192
+ - lib/forecast/version.rb
193
+ - lib/forecastapi.rb
194
+ - lib/forecastcli.rb
195
+ - lib/weather_forecast.rb
196
+ homepage: https://rubygems.org/gems/weather-forecast
197
+ licenses:
198
+ - MIT
199
+ metadata:
200
+ allowed_push_host: https://rubygems.org
201
+ homepage_uri: https://rubygems.org/gems/weather-forecast
202
+ source_code_uri: https://github.com/vanessuniq/weather-forecast
203
+ changelog_uri: https://github.com/vanessuniq/weather-forecast
204
+ post_install_message:
205
+ rdoc_options: []
206
+ require_paths:
207
+ - lib
208
+ required_ruby_version: !ruby/object:Gem::Requirement
209
+ requirements:
210
+ - - ">="
211
+ - !ruby/object:Gem::Version
212
+ version: '0'
213
+ required_rubygems_version: !ruby/object:Gem::Requirement
214
+ requirements:
215
+ - - ">="
216
+ - !ruby/object:Gem::Version
217
+ version: '0'
218
+ requirements: []
219
+ rubygems_version: 3.0.8
220
+ signing_key:
221
+ specification_version: 4
222
+ summary: Gem and CLI providing weather/forecast by zipcode. Weather is provided by
223
+ scraping the OpenWeather website.
224
+ test_files: []