weatherfetch 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: cf006c75b7a296fc87cb804c786192af26df5a948df903db992e7948b6dff89f
4
+ data.tar.gz: 36a5ae3ed3adb669ecb8f58000684e167f033dd38735d6a3683eb7ca04556488
5
+ SHA512:
6
+ metadata.gz: 07d2d07074a94a1c1d6fd9704164de287770797085e4b5657e82dcf9cc9698efa66378799bf53c3fd9f02c10a558112bba152b6d79a3d4a990114189cd9d93fa
7
+ data.tar.gz: bbed18f2e4610d2e46a3963468ea76d70f68be28f83cb06d6677ebbe5cf1534a2279015c86530275d14f2c5a2808ab2889b0084e8b90878902c15e2cb9f5967e
@@ -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,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "weatherfetch"
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
+ WeatherFetch::CLI.start
@@ -0,0 +1,6 @@
1
+ require 'weatherfetch/version'
2
+ require 'weatherfetch/cli'
3
+
4
+ module WeatherFetch
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,93 @@
1
+ require 'httparty'
2
+ require 'thor'
3
+ require 'geocoder'
4
+ require 'terminal-table'
5
+ require 'rainbow'
6
+
7
+ module WeatherFetch
8
+ class CLI < Thor
9
+ def self.exit_on_failure?
10
+ true
11
+ end
12
+
13
+ desc 'current', 'Get current weather for a given city'
14
+ def current(city)
15
+ options = { query: { q: city, appid: 'c8d7f5fd25b8914cc543ed45e6a40bba' } }
16
+ r = HTTParty.get('http://api.openweathermap.org/data/2.5/weather', options)
17
+ puts r
18
+ end
19
+
20
+ desc 'hourly', 'Get hourly weather for a given city'
21
+ def hourly(city)
22
+ response = fetch_city_data(city, 'hourly')
23
+
24
+ rows = response['hourly'].map do |hour|
25
+ [
26
+ Rainbow(Time.at(hour['dt']).strftime('%m/%d %I %p')).darkolivegreen,
27
+ Rainbow("#{hour['temp']}°F").darkolivegreen,
28
+ Rainbow("#{hour['feels_like']}°F").darkolivegreen,
29
+ Rainbow(hour['weather'][0]['description'].capitalize).darkolivegreen,
30
+ Rainbow("#{hour['humidity']}%").darkolivegreen
31
+ ]
32
+ end
33
+
34
+ table = Terminal::Table.new(
35
+ headings: create_headings(['Hour', 'Actual', 'Feels Like', 'Conditions', 'Humidity']),
36
+ rows: rows,
37
+ title: Rainbow(city.capitalize).cornflower
38
+ )
39
+
40
+ puts table
41
+ end
42
+
43
+ desc 'daily', 'Get daily weather for a given city'
44
+ def daily(city)
45
+ response = fetch_city_data(city, 'daily')
46
+
47
+ rows = response['daily'].map do |day|
48
+ [
49
+ Rainbow(Time.at(day['dt']).strftime('%m/%d')).darkolivegreen,
50
+ Rainbow("#{day['temp']['morn']}°F").darkolivegreen,
51
+ Rainbow("#{day['temp']['day']}°F").darkolivegreen,
52
+ Rainbow("#{day['temp']['eve']}°F").darkolivegreen,
53
+ Rainbow("#{day['temp']['night']}°F").darkolivegreen,
54
+ Rainbow(day['weather'][0]['description'].capitalize).darkolivegreen,
55
+ Rainbow("#{day['humidity']}%").darkolivegreen
56
+ ]
57
+ end
58
+
59
+ table = Terminal::Table.new do |t|
60
+ t.headings = create_headings(['Date', 'Morning', 'Afternoon', 'Evening', 'Night', 'Conditions', 'Humidity'])
61
+ t.rows = rows
62
+ t.title = Rainbow(city.capitalize).cornflower
63
+ t.style = { all_separators: :true }
64
+ end
65
+
66
+ puts table
67
+ end
68
+
69
+ private
70
+ def create_headings(headings)
71
+ headings.map { |h| Rainbow(h).red }
72
+ end
73
+
74
+ def fetch_city_data(city, type)
75
+ latitude, longitude = Geocoder.search(city).first.coordinates
76
+
77
+ exclusions = ['hourly', 'minutely', 'current', 'daily'].reject do |ex|
78
+ ex == type
79
+ end
80
+
81
+ options = {
82
+ query: {
83
+ lat: latitude,
84
+ lon: longitude,
85
+ exclude: exclusions.join(','),
86
+ units: 'imperial',
87
+ appid: 'c8d7f5fd25b8914cc543ed45e6a40bba'
88
+ }
89
+ }
90
+ response = HTTParty.get('http://api.openweathermap.org/data/2.5/onecall', options)
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,3 @@
1
+ module WeatherFetch
2
+ VERSION = '0.0.1'
3
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: weatherfetch
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Dylan Andrews
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-06-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.17'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.17'
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.0.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.0.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: rainbow
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: geocoder
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.6.3
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.6.3
69
+ - !ruby/object:Gem::Dependency
70
+ name: terminal-table
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 1.8.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 1.8.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.13'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.13'
97
+ description:
98
+ email:
99
+ - dylanandr@gmail.com
100
+ executables:
101
+ - weatherfetch
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - bin/setup
106
+ - bin/weatherfetch
107
+ - lib/weatherfetch.rb
108
+ - lib/weatherfetch/cli.rb
109
+ - lib/weatherfetch/version.rb
110
+ homepage:
111
+ licenses:
112
+ - MIT
113
+ metadata: {}
114
+ post_install_message:
115
+ rdoc_options: []
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ requirements: []
129
+ rubygems_version: 3.1.2
130
+ signing_key:
131
+ specification_version: 4
132
+ summary: Gem for fetching weather data
133
+ test_files: []