kovid 0.4.5 β 0.4.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +4 -1
- data/lib/kovid.rb +3 -0
- data/lib/kovid/cli.rb +5 -0
- data/lib/kovid/request.rb +35 -28
- data/lib/kovid/tablelize.rb +30 -31
- data/lib/kovid/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: 851facd4cdf0be330b04c5e0f81c91d8a5c5fdaea314751540d224e108c4464d
|
4
|
+
data.tar.gz: b36ce66c70a12df6930ca30d78ccf7628b06d6a4c70563e6382a8db584d96e6a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ef46bb27fef43b9e032dfc81cb05389b22cd199a46f5d0c354794f892552aefb9bc765cc0fde64145e75961086622e29a06de057cc6acb66c192b46c9438890
|
7
|
+
data.tar.gz: f0e2aad02999132f9505586886545116c915d98b90701b6a8f98410b0c27ca64c8990cfe841c75c2096c5023cc11bd0922eafa0ac0258f5e7de3f8e0dd31ede1
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -34,6 +34,10 @@ You can run `kovid --help` to see the full list of available commands.
|
|
34
34
|
You can fetch aggregated data on Africa:
|
35
35
|
* `kovid africa`.
|
36
36
|
|
37
|
+
π°π°π°
|
38
|
+
|
39
|
+
You can fetch aggregated Europe (all 44 countries combined) data:
|
40
|
+
* `kovid europe`.
|
37
41
|
|
38
42
|
πͺπΊπͺπΊπͺπΊ
|
39
43
|
|
@@ -47,7 +51,6 @@ You can fetch US state-specific data:
|
|
47
51
|
|
48
52
|
##### π Upcoming Fetch Features π·ββοΈ
|
49
53
|
|
50
|
-
* `kovid europe` Aggrated stats on Europe
|
51
54
|
* `kovid asia` Aggrated stats on Asia
|
52
55
|
* `kovid south_america` Aggrated stats on South America
|
53
56
|
___
|
data/lib/kovid.rb
CHANGED
data/lib/kovid/cli.rb
CHANGED
data/lib/kovid/request.rb
CHANGED
@@ -10,48 +10,34 @@ module Kovid
|
|
10
10
|
COUNTRIES_PATH = UriBuilder.new('/countries').url
|
11
11
|
STATES_URL = UriBuilder.new('/states').url
|
12
12
|
EU_ISOS = %w[AT BE BG CY CZ DE DK EE ES FI FR GR HR HU IE IT LT LU LV MT NL PL PT RO SE SI SK].freeze
|
13
|
+
EUROPE_ISOS = EU_ISOS + %w[GB IS NO CH MC AD SM VA BA RS ME MK AL BY UA RU MD]
|
13
14
|
AFRICA_ISOS = %w[DZ AO BJ BW BF BI CM CV CF TD KM CD CG CI DJ EG GQ ER SZ ET GA GM GH GN GW KE LS LR LY MG MW ML MR MU MA MZ NA NE NG RW ST SN SC SL SO ZA SS SD TZ TG TN UG ZM ZW EH].freeze
|
15
|
+
|
14
16
|
SERVER_DOWN = 'Server overwhelmed. Please try again in a moment.'
|
15
17
|
|
16
18
|
class << self
|
17
19
|
def eu_aggregate
|
18
|
-
|
19
|
-
|
20
|
-
eu_array = countries_array.select do |hash|
|
21
|
-
EU_ISOS.include?(hash['countryInfo']['iso2'])
|
20
|
+
eu_proc = proc do |data|
|
21
|
+
Kovid::Tablelize.eu_aggregate(data)
|
22
22
|
end
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
left ||= 0
|
27
|
-
right ||= 0
|
24
|
+
aggregator(EU_ISOS, eu_proc)
|
25
|
+
end
|
28
26
|
|
29
|
-
|
30
|
-
|
27
|
+
def europe_aggregate
|
28
|
+
europe_proc = proc do |data|
|
29
|
+
Kovid::Tablelize.europe_aggregate(data)
|
30
|
+
end
|
31
31
|
|
32
|
-
|
33
|
-
rescue JSON::ParserError
|
34
|
-
puts SERVER_DOWN
|
32
|
+
aggregator(EUROPE_ISOS, europe_proc)
|
35
33
|
end
|
36
34
|
|
37
35
|
def africa_aggregate
|
38
|
-
|
39
|
-
|
40
|
-
africa_arry = countries_array.select do |hash|
|
41
|
-
AFRICA_ISOS.include?(hash['countryInfo']['iso2'])
|
36
|
+
africa_proc = proc do |data|
|
37
|
+
Kovid::Tablelize.africa_aggregate(data)
|
42
38
|
end
|
43
39
|
|
44
|
-
|
45
|
-
africa_data = head.merge(*tail) do |key, left, right|
|
46
|
-
left ||= 0
|
47
|
-
right ||= 0
|
48
|
-
|
49
|
-
left + right unless %w[country countryInfo].include?(key)
|
50
|
-
end.compact
|
51
|
-
|
52
|
-
Kovid::Tablelize.africa_aggregate(africa_data)
|
53
|
-
rescue JSON::ParserError
|
54
|
-
puts SERVER_DOWN
|
40
|
+
aggregator(AFRICA_ISOS, africa_proc)
|
55
41
|
end
|
56
42
|
|
57
43
|
def by_country(country_name)
|
@@ -172,6 +158,27 @@ module Kovid
|
|
172
158
|
|
173
159
|
states_array.select { |state_name| state_name['state'] == capitalize_words(state) }.first
|
174
160
|
end
|
161
|
+
|
162
|
+
def aggregator(isos, meth)
|
163
|
+
countries_array = JSON.parse(Typhoeus.get(UriBuilder.new('/countries').url, cache_ttl: 900).response_body)
|
164
|
+
|
165
|
+
country_array = countries_array.select do |hash|
|
166
|
+
isos.include?(hash['countryInfo']['iso2'])
|
167
|
+
end
|
168
|
+
|
169
|
+
head, *tail = country_array
|
170
|
+
data = head.merge(*tail) do |key, left, right|
|
171
|
+
left ||= 0
|
172
|
+
right ||= 0
|
173
|
+
|
174
|
+
left + right unless %w[country countryInfo].include?(key)
|
175
|
+
end.compact
|
176
|
+
|
177
|
+
# Kovid::Tablelize.eu_aggregate(data)
|
178
|
+
meth.call(data)
|
179
|
+
rescue JSON::ParserError
|
180
|
+
puts SERVER_DOWN
|
181
|
+
end
|
175
182
|
end
|
176
183
|
end
|
177
184
|
end
|
data/lib/kovid/tablelize.rb
CHANGED
@@ -271,41 +271,15 @@ module Kovid
|
|
271
271
|
end
|
272
272
|
|
273
273
|
def eu_aggregate(eu_data)
|
274
|
-
|
275
|
-
|
276
|
-
comma_delimit(eu_data['cases']),
|
277
|
-
check_if_positve(eu_data['todayCases']),
|
278
|
-
comma_delimit(eu_data['deaths']),
|
279
|
-
check_if_positve(eu_data['todayDeaths']),
|
280
|
-
comma_delimit(eu_data['recovered']),
|
281
|
-
comma_delimit(eu_data['active']),
|
282
|
-
comma_delimit(eu_data['critical'])
|
283
|
-
]
|
274
|
+
aggregated_table(eu_data, 'The EU', Kovid::Request::EU_ISOS, 'πͺπΊ')
|
275
|
+
end
|
284
276
|
|
285
|
-
|
286
|
-
|
287
|
-
headings: CONTINENTAL_AGGREGATE_HEADINGS,
|
288
|
-
rows: rows
|
289
|
-
)
|
277
|
+
def europe_aggregate(europe_data)
|
278
|
+
aggregated_table(europe_data, 'Europe', Kovid::Request::EUROPE_ISOS, "π°")
|
290
279
|
end
|
291
280
|
|
292
281
|
def africa_aggregate(africa_data)
|
293
|
-
|
294
|
-
rows << [
|
295
|
-
comma_delimit(africa_data['cases']),
|
296
|
-
check_if_positve(africa_data['todayCases']),
|
297
|
-
comma_delimit(africa_data['deaths']),
|
298
|
-
check_if_positve(africa_data['todayDeaths']),
|
299
|
-
comma_delimit(africa_data['recovered']),
|
300
|
-
comma_delimit(africa_data['active']),
|
301
|
-
comma_delimit(africa_data['critical'])
|
302
|
-
]
|
303
|
-
|
304
|
-
Terminal::Table.new(
|
305
|
-
title: 'Aggregated Data of Africa (55 States)'.upcase,
|
306
|
-
headings: CONTINENTAL_AGGREGATE_HEADINGS,
|
307
|
-
rows: rows
|
308
|
-
)
|
282
|
+
aggregated_table(africa_data, 'Africa', Kovid::Request::AFRICA_ISOS, 'π')
|
309
283
|
end
|
310
284
|
|
311
285
|
private
|
@@ -335,6 +309,31 @@ module Kovid
|
|
335
309
|
rows = [[msg]]
|
336
310
|
puts Terminal::Table.new title: 'SCALE', rows: rows
|
337
311
|
end
|
312
|
+
|
313
|
+
def aggregated_table(collated_data, continent, iso, emoji)
|
314
|
+
title = if emoji.codepoints.size > 1
|
315
|
+
emoji + 8203.chr(Encoding::UTF_8) + " Aggregated Data of #{continent} (#{iso.size} States)".upcase
|
316
|
+
else
|
317
|
+
emoji + " Aggregated Data of #{continent} (#{iso.size} States)".upcase
|
318
|
+
end
|
319
|
+
|
320
|
+
rows = []
|
321
|
+
rows << [
|
322
|
+
comma_delimit(collated_data['cases']),
|
323
|
+
check_if_positve(collated_data['todayCases']),
|
324
|
+
comma_delimit(collated_data['deaths']),
|
325
|
+
check_if_positve(collated_data['todayDeaths']),
|
326
|
+
comma_delimit(collated_data['recovered']),
|
327
|
+
comma_delimit(collated_data['active']),
|
328
|
+
comma_delimit(collated_data['critical'])
|
329
|
+
]
|
330
|
+
|
331
|
+
Terminal::Table.new(
|
332
|
+
title: title,
|
333
|
+
headings: CONTINENTAL_AGGREGATE_HEADINGS,
|
334
|
+
rows: rows
|
335
|
+
)
|
336
|
+
end
|
338
337
|
end
|
339
338
|
end
|
340
339
|
end
|
data/lib/kovid/version.rb
CHANGED