kovid 0.4.3 β†’ 0.4.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cc2e30c94c8148c8849241849c6b0340429f0a271ade0927091098972e4fc914
4
- data.tar.gz: 54197f1917738844f1c36e3c1f513deb254d5e47ecb97e8b62db198fded53935
3
+ metadata.gz: bb4f2a55aae94609d2348161b6228065372705e980e4d3e35209a5e1d259371f
4
+ data.tar.gz: 45d8b57b5270fd21831cdb6153914a32a4c8d1dfbca65b922ca84b4443286ee9
5
5
  SHA512:
6
- metadata.gz: 2ebeeeccb550b36ecd7376ba78894434eb2b980c2dbd57e6552e8037400694cf548926e8eea642c0929f974522220804c0a4092344f9f5122df8a5ff257a3695
7
- data.tar.gz: 4f423a115a7c06d937960085e795bb77196f4513434951f1cdf01a3b41ad7892ea561eea73e8046a67a84ff47c4d497b530b08c607af783ddd4e421708091d18
6
+ metadata.gz: 75aa05406a1e3aa47a2f50dd92828c60f559a029e23d6dd155993d8a58c229b0bb90639378b7f5551410cfe9835c6e2bf4f0ea69dc039ab8b69b78f34272a5e1
7
+ data.tar.gz: a3aef9a944a811784c2c1b9503d3f958f76e130ce9698020ed74bcaad9383bcaee76a57fadf0671c4a0fc71a28bd5e6be1f3a14bd9547857159da5b9c48f8627
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kovid (0.4.2)
4
+ kovid (0.4.7)
5
5
  ascii_charts (~> 0.9.1)
6
6
  rainbow (~> 3.0)
7
7
  terminal-table (~> 1.8)
data/README.md CHANGED
@@ -29,22 +29,20 @@ You can run `kovid --help` to see the full list of available commands.
29
29
  * `kovid check COUNTRY` OR `kovid country COUNTRY`.
30
30
  * `kovid check COUNTRY -f` OR `kovid check COUNTRY --full`.
31
31
 
32
- πŸ‡ͺπŸ‡ΊπŸ‡ͺπŸ‡ΊπŸ‡ͺπŸ‡Ί
32
+ You can get continental information with the following commands:
33
33
 
34
- You can fetch aggregated EU (all 27 countries combined) data:
35
- * `kovid eu`.
34
+ * `kovid africa`.
35
+ * `kovid europe`.
36
+ * `kovid eu`. (The European Union)
37
+ * `kovid sa`. (South America)
38
+ * `kovid asia`.
39
+ * `kovid world`. (Worldwide Statistics)
36
40
 
37
41
  πŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡Έ
38
42
 
39
43
  You can fetch US state-specific data:
40
44
  * `kovid state STATE` OR `kovid state "STATE NAME"`.
41
45
 
42
- ##### πŸ”œ Upcoming Fetch Features πŸ‘·β€β™€οΈ
43
-
44
- * `kovid europe` Aggrated stats on Europe
45
- * `kovid africa` Aggrated stats on Africa
46
- * `kovid asia` Aggrated stats on Asia
47
- * `kovid south_america` Aggrated stats on South America
48
46
  ___
49
47
  😷 **Comparing**
50
48
  * `kovid compare FOO BAR` (sorts by cases DESC).
@@ -61,8 +59,6 @@ ___
61
59
  * `kovid history COUNTRY` (full history).
62
60
  * `kovid history COUNTRY N` (history in the last N days).
63
61
  ___
64
- 😷 **Total figures**
65
- * `kovid world` (summary of reported incidents globally).
66
62
 
67
63
  **NOTE:** If you find it irritating to have to type `kovid state STATE`, `covid state STATE` works as well.
68
64
 
@@ -75,19 +71,19 @@ To fetch basic data on a country run:
75
71
 
76
72
  `kovid check ghana`. If the location contains spaces: `kovid check "Diamond Princess"`
77
73
 
78
- ![kovid](https://i.gyazo.com/ee88b41c05da3be0295dd3a158e7ba70.png "Covid data.")
74
+ ![kovid](https://i.gyazo.com/1d86ba2cd05f215b16c8d1fd13085c6e.png "Covid data.")
79
75
 
80
76
  For full table info on a country:
81
77
 
82
78
  `kovid check italy -f` OR `kovid check italy --full`
83
79
 
84
- ![kovid](https://i.gyazo.com/7e5afce548d8a01b9bdf3f8bdb529cd1.png "Covid data.")
80
+ ![kovid](https://i.gyazo.com/1d9720b9fa2c08fb801f5361fba359bb.png "Covid data.")
85
81
 
86
82
  To compare country stats:
87
83
 
88
- `kovid compare germany poland`
84
+ `kovid compare germany poland spain`
89
85
 
90
- ![kovid](https://i.gyazo.com/876b19988da4cd7b375cde3e23376ba7.png "Covid data.")
86
+ ![kovid](https://i.gyazo.com/4100e845fea6936f5c8d21d78617110d.png "Covid data.")
91
87
 
92
88
  To compare a countries stats with a full table:
93
89
 
@@ -107,6 +103,12 @@ To fetch EU data run:
107
103
 
108
104
  ![kovid](https://i.gyazo.com/0a78afae2a5b9d2beb9f2c61dc1d3ac7.png "Covid data.")
109
105
 
106
+ To fetch data on Africa:
107
+
108
+ `kovid africa`
109
+
110
+ ![kovid](https://i.gyazo.com/bc45fa53e2ff688e8a1f759f1bd1b972.png "Covid data.")
111
+
110
112
  You can check historical statistics by running
111
113
 
112
114
  `kovid history italy 7` eg:
@@ -14,6 +14,22 @@ module Kovid
14
14
  Kovid::Request.eu_aggregate
15
15
  end
16
16
 
17
+ def europe_aggregate
18
+ Kovid::Request.europe_aggregate
19
+ end
20
+
21
+ def africa_aggregate
22
+ Kovid::Request.africa_aggregate
23
+ end
24
+
25
+ def south_america_aggregate
26
+ Kovid::Request.south_america_aggregate
27
+ end
28
+
29
+ def asia_aggregate
30
+ Kovid::Request.asia_aggregate
31
+ end
32
+
17
33
  def country(name)
18
34
  Kovid::Request.by_country(name)
19
35
  end
@@ -59,6 +59,30 @@ module Kovid
59
59
  data_source
60
60
  end
61
61
 
62
+ desc 'europe', 'Returns aggregated data on Europe.'
63
+ def europe
64
+ puts Kovid.europe_aggregate
65
+ data_source
66
+ end
67
+
68
+ desc 'africa', 'Returns aggregated data on Africa.'
69
+ def africa
70
+ puts Kovid.africa_aggregate
71
+ data_source
72
+ end
73
+
74
+ desc 'sa', 'Returns aggregated data on South America.'
75
+ def sa
76
+ puts Kovid.south_america_aggregate
77
+ data_source
78
+ end
79
+
80
+ desc 'asia', 'Returns aggregated data on Asia.'
81
+ def asia
82
+ puts Kovid.asia_aggregate
83
+ data_source
84
+ end
85
+
62
86
  desc 'version', 'Returns version of kovid'
63
87
  def version
64
88
  puts Kovid::VERSION
@@ -10,27 +10,52 @@ 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]
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
+ SOUTH_AMERICA_ISOS = ['AR' 'BO', 'BV', 'BR', 'CL', 'CO', 'EC', 'FK', 'GF', 'GY', 'PY', 'PE', 'GS', 'SR', 'UY', 'VE'].freeze
16
+ ASIA_ISOS = %w[AE AF AM AZ BD BH BN BT CC CN CX GE HK ID IL IN IQ IR JO JP KG KH KP KR KW KZ LA LB LK MM MN MO MY NP OM PH PK PS QA SA SG SY TH TJ TL TM TR TW UZ VN YE].freeze
17
+
13
18
  SERVER_DOWN = 'Server overwhelmed. Please try again in a moment.'
14
19
 
15
20
  class << self
16
21
  def eu_aggregate
17
- countries_array = JSON.parse(Typhoeus.get(UriBuilder.new('/countries').url, cache_ttl: 900).response_body)
22
+ eu_proc = proc do |data|
23
+ Kovid::Tablelize.eu_aggregate(data)
24
+ end
25
+
26
+ aggregator(EU_ISOS, eu_proc)
27
+ end
18
28
 
19
- eu_array = countries_array.select do |hash|
20
- EU_ISOS.include?(hash['countryInfo']['iso2'])
29
+ def europe_aggregate
30
+ europe_proc = proc do |data|
31
+ Kovid::Tablelize.europe_aggregate(data)
21
32
  end
22
33
 
23
- head, *tail = eu_array
24
- eu_data = head.merge(*tail) do |key, left, right|
25
- left ||= 0
26
- right ||= 0
34
+ aggregator(EUROPE_ISOS, europe_proc)
35
+ end
27
36
 
28
- left + right unless %w[country countryInfo].include?(key)
29
- end.compact
37
+ def africa_aggregate
38
+ africa_proc = proc do |data|
39
+ Kovid::Tablelize.africa_aggregate(data)
40
+ end
30
41
 
31
- Kovid::Tablelize.eu_aggregate(eu_data)
32
- rescue JSON::ParserError
33
- puts SERVER_DOWN
42
+ aggregator(AFRICA_ISOS, africa_proc)
43
+ end
44
+
45
+ def south_america_aggregate
46
+ south_america_proc = proc do |data|
47
+ Kovid::Tablelize.south_america_aggregate(data)
48
+ end
49
+
50
+ aggregator(SOUTH_AMERICA_ISOS, south_america_proc)
51
+ end
52
+
53
+ def asia_aggregate
54
+ asia_proc = proc do |data|
55
+ Kovid::Tablelize.asia_aggregate(data)
56
+ end
57
+
58
+ aggregator(ASIA_ISOS, asia_proc)
34
59
  end
35
60
 
36
61
  def by_country(country_name)
@@ -151,6 +176,26 @@ module Kovid
151
176
 
152
177
  states_array.select { |state_name| state_name['state'] == capitalize_words(state) }.first
153
178
  end
179
+
180
+ def aggregator(isos, meth)
181
+ countries_array = JSON.parse(Typhoeus.get(UriBuilder.new('/countries').url, cache_ttl: 900).response_body)
182
+
183
+ country_array = countries_array.select do |hash|
184
+ isos.include?(hash['countryInfo']['iso2'])
185
+ end
186
+
187
+ head, *tail = country_array
188
+ data = head.merge(*tail) do |key, left, right|
189
+ left ||= 0
190
+ right ||= 0
191
+
192
+ left + right unless %w[country countryInfo].include?(key)
193
+ end.compact
194
+
195
+ meth === data
196
+ rescue JSON::ParserError
197
+ puts SERVER_DOWN
198
+ end
154
199
  end
155
200
  end
156
201
  end
@@ -28,7 +28,7 @@ module Kovid
28
28
  'Deaths'.paint_red
29
29
  ].freeze
30
30
 
31
- EU_AGGREGATE_HEADINGS = [
31
+ CONTINENTAL_AGGREGATE_HEADINGS = [
32
32
  'Cases'.paint_white,
33
33
  'Cases Today'.paint_white,
34
34
  'Deaths'.paint_red,
@@ -49,6 +49,15 @@ module Kovid
49
49
  'Cases/Million'.paint_white
50
50
  ].freeze
51
51
 
52
+ COMPARE_COUNTRIES_TABLE_HEADINGS = [
53
+ 'Country'.paint_white,
54
+ 'Cases'.paint_white,
55
+ 'Cases Today'.paint_white,
56
+ 'Deaths'.paint_red,
57
+ 'Deaths Today'.paint_red,
58
+ 'Recovered'.paint_green
59
+ ].freeze
60
+
52
61
  FOOTER_LINE = ['------------', '------------', '------------'].freeze
53
62
  COUNTRY_LETTERS = 'A'.upto('Z').with_index(127_462).to_h.freeze
54
63
 
@@ -69,8 +78,6 @@ module Kovid
69
78
  else
70
79
  Terminal::Table.new(title: data['country'].upcase, headings: headings, rows: rows)
71
80
  end
72
- # TODO: Rafactor this
73
- # TODO: Fix emoji
74
81
  end
75
82
 
76
83
  def full_country_table(data)
@@ -123,29 +130,25 @@ module Kovid
123
130
  end
124
131
 
125
132
  def compare_countries_table(data)
126
- headings = [
127
- 'Country'.paint_white,
128
- 'Cases'.paint_white,
129
- 'Deaths'.paint_red,
130
- 'Recovered'.paint_green,
131
- 'Cases Today'.paint_white,
132
- 'Deaths Today'.paint_red
133
- ]
134
-
135
133
  rows = []
136
134
 
137
135
  data.each do |country|
138
- rows << [
139
- country['country'].upcase,
136
+ base_rows = [
140
137
  comma_delimit(country['cases']),
141
- comma_delimit(country['deaths']),
142
- comma_delimit(country['recovered']),
143
138
  check_if_positve(country['todayCases']),
144
- check_if_positve(country['todayDeaths'])
139
+ comma_delimit(country['deaths']),
140
+ check_if_positve(country['todayDeaths']),
141
+ comma_delimit(country['recovered'])
145
142
  ]
143
+
144
+ rows << if iso = country['countryInfo']['iso2']
145
+ base_rows.unshift("#{country_emoji(iso)} #{country['country'].upcase}")
146
+ else
147
+ base_rows.unshift(country['country'].upcase.to_s)
148
+ end
146
149
  end
147
150
 
148
- Terminal::Table.new(headings: headings, rows: rows)
151
+ Terminal::Table.new(headings: COMPARE_COUNTRIES_TABLE_HEADINGS, rows: rows)
149
152
  end
150
153
 
151
154
  def compare_countries_table_full(data)
@@ -159,7 +162,6 @@ module Kovid
159
162
  check_if_positve(country.fetch('todayDeaths')),
160
163
  comma_delimit(country.fetch('critical')),
161
164
  comma_delimit(country.fetch('casesPerOneMillion'))
162
-
163
165
  ]
164
166
  end
165
167
 
@@ -269,22 +271,25 @@ module Kovid
269
271
  end
270
272
 
271
273
  def eu_aggregate(eu_data)
272
- rows = []
273
- rows << [
274
- comma_delimit(eu_data['cases']),
275
- check_if_positve(eu_data['todayCases']),
276
- comma_delimit(eu_data['deaths']),
277
- check_if_positve(eu_data['todayDeaths']),
278
- comma_delimit(eu_data['recovered']),
279
- comma_delimit(eu_data['active']),
280
- comma_delimit(eu_data['critical'])
281
- ]
274
+ aggregated_table(eu_data, 'The EU', Kovid::Request::EU_ISOS, 'πŸ‡ͺπŸ‡Ί')
275
+ end
282
276
 
283
- Terminal::Table.new(
284
- title: 'πŸ‡ͺπŸ‡Ί' + 8203.chr(Encoding::UTF_8) + ' Aggregated EU (27 States) Data'.upcase,
285
- headings: EU_AGGREGATE_HEADINGS,
286
- rows: rows
287
- )
277
+ def europe_aggregate(europe_data)
278
+ aggregated_table(europe_data, 'Europe', Kovid::Request::EUROPE_ISOS, '🏰')
279
+ end
280
+
281
+ def africa_aggregate(africa_data)
282
+ aggregated_table(africa_data, 'Africa', Kovid::Request::AFRICA_ISOS, '🌍')
283
+ end
284
+
285
+ def south_america_aggregate(south_america_data)
286
+ aggregated_table(south_america_data,
287
+ 'South America',
288
+ Kovid::Request::SOUTH_AMERICA_ISOS, '🌎')
289
+ end
290
+
291
+ def asia_aggregate(asia_data)
292
+ aggregated_table(asia_data, 'Asia', Kovid::Request::ASIA_ISOS, '🌏')
288
293
  end
289
294
 
290
295
  private
@@ -301,7 +306,8 @@ module Kovid
301
306
  end
302
307
 
303
308
  def country_emoji(iso)
304
- COUNTRY_LETTERS.values_at(*iso.chars).pack('U*') + 8203.chr(Encoding::UTF_8)
309
+ COUNTRY_LETTERS.values_at(*iso.chars).pack('U*') + \
310
+ 8203.chr(Encoding::UTF_8)
305
311
  end
306
312
 
307
313
  def transpose(load)
@@ -314,6 +320,33 @@ module Kovid
314
320
  rows = [[msg]]
315
321
  puts Terminal::Table.new title: 'SCALE', rows: rows
316
322
  end
323
+
324
+ def aggregated_table(collated_data, continent, iso, emoji)
325
+ title = if emoji.codepoints.size > 1
326
+ emoji + 8203.chr(Encoding::UTF_8) + \
327
+ " Aggregated Data on #{continent} (#{iso.size} States)".upcase
328
+ else
329
+ emoji + \
330
+ " Aggregated Data on #{continent} (#{iso.size} States)".upcase
331
+ end
332
+
333
+ rows = []
334
+ rows << [
335
+ comma_delimit(collated_data['cases']),
336
+ check_if_positve(collated_data['todayCases']),
337
+ comma_delimit(collated_data['deaths']),
338
+ check_if_positve(collated_data['todayDeaths']),
339
+ comma_delimit(collated_data['recovered']),
340
+ comma_delimit(collated_data['active']),
341
+ comma_delimit(collated_data['critical'])
342
+ ]
343
+
344
+ Terminal::Table.new(
345
+ title: title,
346
+ headings: CONTINENTAL_AGGREGATE_HEADINGS,
347
+ rows: rows
348
+ )
349
+ end
317
350
  end
318
351
  end
319
352
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kovid
4
- VERSION = '0.4.3'
4
+ VERSION = '0.4.8'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kovid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emmanuel Hayford
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-03-28 00:00:00.000000000 Z
11
+ date: 2020-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor