weatherfetch 0.0.3 → 0.0.4
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 +4 -4
- data/lib/weatherfetch/cli.rb +35 -15
- data/lib/weatherfetch/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d07efd25e4be1cd983bcda4169cf7fe0180f78c287d5cf251925e437f89ad8fa
|
4
|
+
data.tar.gz: 5fdd836833b35e52e93599bca127e663cbaf2944392a137027e67ccf5e2eb1e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c7577a516a7e3f934eb9524812814a8f6b5c417c2e5631c2bc8e94557086224da895d60f7cad7ac26387e30480c57bd0b6da07e2bf53f48f5ec033876d5ec9e4
|
7
|
+
data.tar.gz: c76bec63c2522b511db4c4004056f61545889edce7ff5dc53de781524e999ee6821074e4c006ce643dd23c300c77e6f8a3488789fd4fb513175dcb592f77d40a
|
data/lib/weatherfetch/cli.rb
CHANGED
@@ -27,7 +27,7 @@ module WeatherFetch
|
|
27
27
|
table = Terminal::Table.new(
|
28
28
|
headings: create_headings(['Hour', 'Actual', 'Feels Like', 'Conditions', 'Humidity']),
|
29
29
|
rows: rows,
|
30
|
-
title: "
|
30
|
+
title: "#{Rainbow(get_title).cornflower}"
|
31
31
|
)
|
32
32
|
|
33
33
|
puts table
|
@@ -54,7 +54,7 @@ module WeatherFetch
|
|
54
54
|
table = Terminal::Table.new do |t|
|
55
55
|
t.headings = create_headings(['Date', 'Min', 'Max', 'Morning', 'Afternoon', 'Evening', 'Night', 'Conditions', 'Humidity'])
|
56
56
|
t.rows = rows
|
57
|
-
t.title = "
|
57
|
+
t.title = "#{Rainbow(get_title).cornflower}"
|
58
58
|
t.style = { all_separators: :true }
|
59
59
|
end
|
60
60
|
|
@@ -66,23 +66,43 @@ module WeatherFetch
|
|
66
66
|
headings.map { |h| Rainbow(h).red }
|
67
67
|
end
|
68
68
|
|
69
|
-
def
|
70
|
-
|
69
|
+
def get_title
|
70
|
+
city = @location_data.data.dig('address', 'city')
|
71
|
+
country = @location_data.data.dig('address', 'country_code').upcase
|
72
|
+
state = @location_data.data.dig('address', 'state')
|
73
|
+
|
74
|
+
cleaned_city = city && city.split('-').first
|
75
|
+
flag = country.tr('A-Z', "\u{1F1E6}-\u{1F1FF}")
|
71
76
|
|
72
|
-
|
73
|
-
|
77
|
+
title = [cleaned_city, state, country].each_with_object('') do |loc, str|
|
78
|
+
str << "#{loc}, " if loc
|
74
79
|
end
|
75
80
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
81
|
+
"#{flag} #{title.delete_suffix(', ')} #{flag}"
|
82
|
+
end
|
83
|
+
|
84
|
+
def fetch_location_data(location, type)
|
85
|
+
if @location_data = Geocoder.search(location).first
|
86
|
+
latitude, longitude = @location_data.coordinates
|
87
|
+
|
88
|
+
exclusions = ['hourly', 'minutely', 'current', 'daily'].reject do |ex|
|
89
|
+
ex == type
|
90
|
+
end
|
91
|
+
|
92
|
+
options = {
|
93
|
+
query: {
|
94
|
+
lat: latitude,
|
95
|
+
lon: longitude,
|
96
|
+
exclude: exclusions.join(','),
|
97
|
+
units: 'imperial',
|
98
|
+
appid: 'c8d7f5fd25b8914cc543ed45e6a40bba'
|
99
|
+
}
|
83
100
|
}
|
84
|
-
|
85
|
-
|
101
|
+
response = HTTParty.get('http://api.openweathermap.org/data/2.5/onecall', options)
|
102
|
+
else
|
103
|
+
puts Rainbow('Please enter a valid location').red
|
104
|
+
exit
|
105
|
+
end
|
86
106
|
end
|
87
107
|
end
|
88
108
|
end
|
data/lib/weatherfetch/version.rb
CHANGED