weather_lookup 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 645157142b24b95f893796cea7a54b9f2d9f2a80
4
+ data.tar.gz: fdd9c2104f548705d35062a853551930a9797107
5
+ SHA512:
6
+ metadata.gz: 1f9fd716f931e89056022adb0da128ad85d8506c83b577846b743011606a35ef8fbf53b8296382cc43669bcb157c2fef78eaf32207e5b51b92abd83693f41b1d
7
+ data.tar.gz: 5392785a7048f9b44e998abf575826e9428b022ffd1b0985594b243022c757f7f8e28931b83d21a5c3ddd320175279d86a51d98f86108dbcd9568597f476ec63
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at erickentleongchu@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in weather_lookup.gemspec
4
+ gemspec
5
+
6
+ gem 'pry'
7
+ gem 'nokogiri'
8
+ gem 'paint'
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2016 Eric Chu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Eric Chu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,35 @@
1
+ # WeatherLookup
2
+
3
+ Hi, This is a weather lookup cli. :D
4
+
5
+ You can run the program with ./bin/weather_lookup
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'weather-lookup-cli-gem'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install weather-lookup-cli-gem
22
+
23
+ ## Usage
24
+
25
+ Enter 5 digit zipcode and it will return the city/state/time/weather/temp.
26
+
27
+
28
+ ## Contributing
29
+
30
+ Bug reports and pull requests are welcome on GitHub at https://github.com/KentLeong/weather_lookup. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
31
+
32
+
33
+ ## License
34
+
35
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "weather_lookup"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/weather_lookup'
4
+
5
+ WeatherLookup::CLI.new.call
@@ -0,0 +1,7 @@
1
+ require 'open-uri'
2
+ require 'pry'
3
+ require 'nokogiri'
4
+
5
+ require_relative "./weather_lookup/version"
6
+ require_relative "./weather_lookup/cli"
7
+ require_relative "./weather_lookup/weather"
@@ -0,0 +1,94 @@
1
+ require 'pry'
2
+ require 'nokogiri'
3
+ require 'open-uri'
4
+ require 'paint'
5
+ require 'date'
6
+
7
+ class WeatherLookup::CLI
8
+ #sky blue
9
+ PRIMARY_COLOR = "5fcbf5"
10
+ #light blue
11
+ SECONDARY_COLOR = "2bafe3"
12
+ #dark blue
13
+ DARK_COLOR = "063175"
14
+
15
+ def call
16
+ welcome_greeting
17
+ get_zip
18
+ end
19
+
20
+ def welcome_greeting
21
+ puts_line_bar
22
+ puts Paint["Welcome to Weather Lookup", PRIMARY_COLOR]
23
+ puts Paint["The current season is #{current_season}", DARK_COLOR]
24
+ puts_line_bar
25
+ puts "Enter a zipcode: "
26
+ puts_line_bar
27
+ end
28
+
29
+ def get_zip
30
+ input = nil
31
+ while input != "exit"
32
+ input = gets.strip.downcase
33
+ if zip_valid?(input)
34
+ data = WeatherLookup::Weather.scrape_wunderground(input)
35
+
36
+ puts_line_bar
37
+ puts Paint["#{data.location} #{data.zip}:", PRIMARY_COLOR]
38
+
39
+ #Color is inbtween Primary and Dark Color
40
+ puts Paint["#{data.time}", "4873b8"]
41
+ #Color is inbtween Primary and Dark Color
42
+ puts Paint["The Weather is #{data.weather}", "20498a"]
43
+
44
+ puts Paint["Temperture: #{data.current_temp}°F", DARK_COLOR]
45
+ puts_line_bar
46
+ puts "Would you like to look up another zip or exit?"
47
+ puts_line_bar
48
+ elsif input == "exit"
49
+ puts_line_bar
50
+ puts "goodbye!"
51
+ puts_line_bar
52
+ else
53
+ puts_line_bar
54
+ puts Paint["Try again, Zip must be 5 numbers.", "red"]
55
+ puts Paint["or exit by inputing exit", "red"]
56
+ puts_line_bar
57
+ end
58
+ end
59
+ end
60
+
61
+ private
62
+ def puts_line_bar
63
+ puts Paint["-----------------------------------------------", SECONDARY_COLOR]
64
+ end
65
+
66
+ def zip_valid?(input)
67
+ if input.size != 5
68
+ false
69
+ else
70
+ begin
71
+ Nokogiri::HTML(open("https://www.wunderground.com/cgi-bin/findweather/getForecast?query=#{input}"))
72
+ rescue OpenURI::HTTPError => e
73
+ if e.message == '404 Not Found'
74
+ puts_line_bar
75
+ puts Paint["404 Error; Zip does not exist!", "red"]
76
+ end
77
+ end
78
+ end
79
+ end
80
+
81
+ def current_season
82
+ current_month = Date.today.strftime("%m").to_i
83
+ case current_month
84
+ when 3..5
85
+ "Spring"
86
+ when 6..8
87
+ "Summer"
88
+ when 9..11
89
+ "Autumn"
90
+ when 1..2 || 12
91
+ "Winter"
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,3 @@
1
+ module WeatherLookup
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,46 @@
1
+ require 'pry'
2
+ require 'nokogiri'
3
+ require 'open-uri'
4
+ class WeatherLookup::Weather
5
+ attr_accessor :weather, :current_temp, :location, :time, :zip
6
+
7
+ def initialize(attributes = {})
8
+ @weather = attributes[:weather]
9
+ @current_temp = attributes[:current_temp]
10
+ @location = attributes[:location]
11
+ @time = attributes[:time]
12
+ @zip = attributes[:zip]
13
+ end
14
+
15
+ # Weather.new({weather: 'Sunny', current_temp: 76, location: 'San Diego, CA', time: '8:12 AM'})
16
+
17
+ # def get_data
18
+ # scrape_wunderground # :weather, :current_temp, :location, :zip, :time, :forcast
19
+ # end
20
+
21
+ # private
22
+ def self.scrape_wunderground(zip)
23
+ doc = Nokogiri::HTML(open("https://www.wunderground.com/cgi-bin/findweather/getForecast?query=#{zip}"))
24
+ self.new({
25
+ current_temp: /\d{2}(?:.\d)?/.match(doc.search("div.small-6.columns").text).to_s,
26
+ location: doc.search("h1.city-nav-header").text.split("\n\t\t")[1],
27
+ weather: doc.search("div#curCond").text,
28
+ time: doc.search("div.local-time").text.sub(' ', ''),
29
+ zip: zip
30
+ })
31
+ # temp = doc.search("div.small-6.columns").text
32
+ # @current_temp = /\d{2}(?:.\d)?/.match(temp).to_s
33
+
34
+ # location = doc.search("h1.city-nav-header").text
35
+ # @location = location.split("\n\t\t")[1]
36
+
37
+ # weather = doc.search("div#curCond").text
38
+ # @weather = weather
39
+ #
40
+ # time = doc.search("div.local-time").text
41
+ # time.slice!(0)
42
+ # @time = time
43
+ end
44
+
45
+ #scrape weather.com
46
+ end
data/spec.md ADDED
@@ -0,0 +1,6 @@
1
+ # Specifications for the CLI Assessment
2
+
3
+ Specs:
4
+ - [x] Have a CLI for interfacing with the application
5
+ - [x] Pull data from an external source
6
+ - [x] Implement both list and detail views
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'weather_lookup/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "weather_lookup"
8
+ spec.version = WeatherLookup::VERSION
9
+ spec.authors = ["Eric Chu"]
10
+ spec.email = ["LeongZeno@gmail.com"]
11
+
12
+ spec.summary = %q{Hi, you can look up your weather with your zipcode with this.}
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files`.split($\)
16
+ spec.executables = ['weather_lookup']
17
+ spec.require_paths = ["lib", "lib/weather_lookup"]
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.12"
20
+ spec.add_development_dependency "rake", "~> 10.0"
21
+ spec.add_development_dependency "rspec"
22
+ spec.add_development_dependency "nokogiri"
23
+ spec.add_development_dependency "pry"
24
+ spec.add_development_dependency "paint"
25
+ spec.add_development_dependency "date"
26
+ end
metadata ADDED
@@ -0,0 +1,160 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: weather_lookup
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Eric Chu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-09-07 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.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
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: :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: pry
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: paint
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: date
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
+ description:
112
+ email:
113
+ - LeongZeno@gmail.com
114
+ executables:
115
+ - weather_lookup
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - CODE_OF_CONDUCT.md
121
+ - Gemfile
122
+ - LICENSE
123
+ - LICENSE.txt
124
+ - README.md
125
+ - Rakefile
126
+ - bin/console
127
+ - bin/setup
128
+ - bin/weather_lookup
129
+ - lib/weather_lookup.rb
130
+ - lib/weather_lookup/cli.rb
131
+ - lib/weather_lookup/version.rb
132
+ - lib/weather_lookup/weather.rb
133
+ - spec.md
134
+ - weather_lookup.gemspec
135
+ homepage:
136
+ licenses:
137
+ - MIT
138
+ metadata: {}
139
+ post_install_message:
140
+ rdoc_options: []
141
+ require_paths:
142
+ - lib
143
+ - lib/weather_lookup
144
+ required_ruby_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ required_rubygems_version: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ requirements: []
155
+ rubyforge_project:
156
+ rubygems_version: 2.6.4
157
+ signing_key:
158
+ specification_version: 4
159
+ summary: Hi, you can look up your weather with your zipcode with this.
160
+ test_files: []