kovid 0.2.5 → 0.3.1

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: b453d783796a94766fee3d796a41070ae4a1708c8a306a8b77ae60a912293a78
4
- data.tar.gz: 85ff2d518cd223ab521f6c1221151745a75269605288fcd5882f569871bbc0eb
3
+ metadata.gz: ced083e926d055a20281a468cc923214709badda8fa4a489bcbaa2a0a30aecfa
4
+ data.tar.gz: 88f862b715a3ba136683511700f68edfa2c25716e373152b4151ebaaf717e184
5
5
  SHA512:
6
- metadata.gz: 9d4d98b52a3eea164950abbb4639c97aacd95f3a3cce00f8d211c558ec5fc3f97bbb26bf2b97aab69ad95bbc897c77c9a65bd66a97e5f3021bb48adc23e007af
7
- data.tar.gz: 19f9ce8011ecf1383c71787fd9bc853d4fef3d3df2bbb6d63010e0a4bffa6708d895ed05547c4db6629f9fe84028dc614e0b9de5951b603f8fd2e162b7de6473
6
+ metadata.gz: a265dcf1170bed905c522ae4aa038b2368561f9aed9c56c1f3e8dd8db89464a4c8ed576b215f94c1a2a4f9687e4e754f3c12ad1dd24a1a30c316c700e04eb93f
7
+ data.tar.gz: 58780c213b132e4b5047386d8c03f3127a09ab51512d09892eaa1ea4ddeb08d507daaa335658746fd6579b85758a1d2eba2cc28906217ecbac6d4c41c37e3282
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kovid (0.2.4)
5
- colorize (~> 0.8)
4
+ kovid (0.3.0)
5
+ rainbow (~> 3.0)
6
6
  terminal-table (~> 1.8)
7
7
  thor (~> 1.0)
8
8
  typhoeus (~> 1.3)
@@ -21,7 +21,6 @@ GEM
21
21
  builder (3.2.4)
22
22
  childprocess (3.0.0)
23
23
  coderay (1.1.2)
24
- colorize (0.8.1)
25
24
  contracts (0.16.0)
26
25
  cucumber (3.1.2)
27
26
  builder (>= 2.1.2)
@@ -51,6 +50,7 @@ GEM
51
50
  pry (0.12.2)
52
51
  coderay (~> 1.1.0)
53
52
  method_source (~> 0.9.0)
53
+ rainbow (3.0.0)
54
54
  rake (12.3.3)
55
55
  rspec (3.9.0)
56
56
  rspec-core (~> 3.9.0)
@@ -89,4 +89,4 @@ DEPENDENCIES
89
89
  simplecov
90
90
 
91
91
  BUNDLED WITH
92
- 2.1.2
92
+ 2.1.4
data/README.md CHANGED
@@ -4,7 +4,8 @@
4
4
 
5
5
  Kovid is a small CLI app to fetch data surrounding the coronavirus pandemic of 2019. I found myself checking [Wikipedia](https://en.wikipedia.org/wiki/2019%E2%80%9320_coronavirus_pandemic) constantly for information and since I work mostly in the terminal, like some of you, I thought I'd build this to put the data right at our fingertips.
6
6
 
7
- Please feel free to contribute or suggest ideas!
7
+ Code contribution and ideas welcome.
8
+
8
9
 
9
10
  ## ⚙️ Installation
10
11
 
@@ -14,6 +15,8 @@ Before installing:
14
15
 
15
16
  ✌️ Run `gem install kovid`
16
17
 
18
+ UPDATE often with `gem update kovid`
19
+
17
20
 
18
21
 
19
22
  ## ⚒️ Usage
@@ -24,7 +27,7 @@ You can run `kovid --help` to see the full list of available commands.
24
27
 
25
28
  #### Commands Overview
26
29
  😷 **Fetching**
27
- * `kovid check COUNTRY`
30
+ * `kovid check COUNTRY` (`kovid country COUNTRY` works as well)
28
31
  * `kovid check COUNTRY -f` OR `kovid check COUNTRY --full`
29
32
 
30
33
  🇺🇸You can fetch US state-specific data 🇺🇸
@@ -37,8 +40,8 @@ You can run `kovid --help` to see the full list of available commands.
37
40
  You can compare as many countries as you want.
38
41
 
39
42
  😷 **History**
40
- * `kovid history COUNTRY` (Full history)
41
- * `kovid history COUNTRY N` (History in the last N days)
43
+ * `kovid history COUNTRY` (full history)
44
+ * `kovid history COUNTRY N` (history in the last N days)
42
45
 
43
46
  😷 **Total figures**
44
47
  * `kovid cases`
@@ -48,7 +48,7 @@ Gem::Specification.new do |spec|
48
48
  spec.add_dependency "thor", "~> 1.0"
49
49
  spec.add_dependency "terminal-table", "~> 1.8"
50
50
  spec.add_dependency "typhoeus", "~> 1.3"
51
- spec.add_dependency "colorize", "~> 0.8"
51
+ spec.add_dependency "rainbow", "~> 3.0"
52
52
 
53
53
  spec.add_development_dependency "pry"
54
54
  spec.add_development_dependency "cucumber"
@@ -21,8 +21,16 @@ module Kovid
21
21
  puts Kovid.country(name)
22
22
  end
23
23
  end
24
+
24
25
  desc 'country COUNTRY or country "COUNTRY NAME"', 'Returns reported data on provided country. eg: "kovid country "hong kong".'
25
- alias country check
26
+ method_option :full, aliases: '-f'
27
+ def country(name)
28
+ if options[:full]
29
+ puts Kovid.country_full(name)
30
+ else
31
+ puts Kovid.country(name)
32
+ end
33
+ end
26
34
 
27
35
  desc 'state STATE', 'Return reported data on provided state.'
28
36
  def state(state)
@@ -43,7 +51,7 @@ module Kovid
43
51
  puts Kovid.cases
44
52
  end
45
53
 
46
- desc 'history COUNTRY', 'Return history of incidents of COUNTRY'
54
+ desc 'history COUNTRY or history COUNTRY N', 'Return history of incidents of COUNTRY (in the last N days)'
47
55
  def history(*params)
48
56
  if params.size == 2
49
57
  puts Kovid.history(params.first, params.last)
@@ -1,21 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'colorize'
3
+ require 'rainbow'
4
4
 
5
5
  class String
6
6
  def paint_white
7
- colorize(:white).colorize(background: :black).colorize(mode: :bold)
7
+ Rainbow(self).white.bg(:black).bold
8
8
  end
9
9
 
10
10
  def paint_red
11
- colorize(:red).colorize(background: :black).colorize(mode: :bold)
11
+ Rainbow(self).red.bg(:black).bold
12
12
  end
13
13
 
14
14
  def paint_green
15
- colorize(:green).colorize(background: :black).colorize(mode: :bold)
15
+ Rainbow(self).green.bg(:black).bold
16
16
  end
17
17
 
18
18
  def paint_yellow
19
- colorize(:yellow).colorize(background: :black).colorize(mode: :bold)
19
+ Rainbow(self).yellow.bg(:black).bold
20
20
  end
21
21
  end
@@ -8,6 +8,7 @@ require_relative 'uri_builder'
8
8
  module Kovid
9
9
  class Request
10
10
  COUNTRIES_PATH = UriBuilder.new('/countries').url
11
+ STATES_URL = UriBuilder.new('/states').url
11
12
 
12
13
  class << self
13
14
  def by_country(country_name)
@@ -58,7 +59,7 @@ module Kovid
58
59
  private
59
60
 
60
61
  def no_case_in(country)
61
- rows = [['No reported cases OR check your spelling!']]
62
+ rows = [['No reported cases OR wrong spelling of country/state!']]
62
63
  Terminal::Table.new headings: ["You checked: #{country.capitalize}"], rows: rows
63
64
  end
64
65
 
@@ -73,21 +74,17 @@ module Kovid
73
74
  end
74
75
 
75
76
  def fetch_country(country_name)
76
- url = COUNTRIES_PATH + "/#{country_name}"
77
+ country_url = COUNTRIES_PATH + "/#{country_name}"
77
78
 
78
- JSON.parse(Typhoeus.get(url, cache_ttl: 900).response_body)
79
+ JSON.parse(Typhoeus.get(country_url, cache_ttl: 900).response_body)
79
80
  end
80
81
 
81
82
  def fetch_state(state)
82
- url = UriBuilder.new('/states').url
83
-
84
- states_array = JSON.parse(Typhoeus.get(url, cache_ttl: 900).response_body)
83
+ states_array = JSON.parse(Typhoeus.get(STATES_URL, cache_ttl: 900).response_body)
85
84
 
86
85
  states_array.select { |state_name| state_name['state'] == capitalize_words(state) }.first
87
86
  end
88
87
 
89
- private
90
-
91
88
  def capitalize_words(string)
92
89
  string.split.map(&:capitalize).join(' ')
93
90
  end
@@ -21,12 +21,19 @@ module Kovid
21
21
  ].freeze
22
22
 
23
23
  FOOTER_LINE = ['------------', '------------', '------------', '------------'].freeze
24
+ COUNTRY_LETTERS = 'A'.upto('Z').with_index(127_462).to_h.freeze
24
25
 
25
26
  def country_table(data)
26
27
  headings = CASES_DEATHS_RECOVERED
27
28
  rows = [[data['cases'], data['deaths'], data['recovered']]]
28
29
 
29
- Terminal::Table.new(title: data['country'].upcase, headings: headings, rows: rows)
30
+ if iso = data['countryInfo']['iso2']
31
+ Terminal::Table.new(title: "#{data['country'].upcase}", headings: headings, rows: rows)
32
+ else
33
+ Terminal::Table.new(title: data['country'].upcase, headings: headings, rows: rows)
34
+ end
35
+ # TODO: Rafactor this
36
+ # TODO: Fix emoji
30
37
  end
31
38
 
32
39
  def full_country_table(data)
@@ -45,14 +52,22 @@ module Kovid
45
52
  data['cases'],
46
53
  data['deaths'],
47
54
  data['recovered'],
48
- data['todayCases'],
49
- data['todayDeaths'],
55
+ check_if_positve(data['todayCases']),
56
+ check_if_positve(data['todayDeaths']),
50
57
  data['critical'],
51
58
  data['casesPerOneMillion']
52
59
  ]
53
- Terminal::Table.new(title: data['country'].upcase,
54
- headings: headings,
55
- rows: rows)
60
+
61
+ # if iso = data['countryInfo']['iso2']
62
+ # Terminal::Table.new(title: "#{data['country'].upcase} #{country_emoji(iso)}",
63
+ # headings: headings,
64
+ # rows: rows)
65
+ # else
66
+ Terminal::Table.new(title: data['country'].upcase,
67
+ headings: headings,
68
+ rows: rows)
69
+ # end
70
+ # TODO: Rafactor this
56
71
  end
57
72
 
58
73
  def full_state_table(state)
@@ -61,16 +76,11 @@ module Kovid
61
76
  'Cases Today'.paint_white,
62
77
  'Deaths'.paint_red,
63
78
  'Deaths Today'.paint_red,
64
- 'Recovered'.paint_green,
65
79
  'Active'.paint_yellow
66
80
  ]
67
81
 
68
82
  rows = []
69
- rows << [state['cases'], state['todayCases'], state['deaths'], state['todayDeaths'], state['recovered'], state['active']]
70
-
71
- puts
72
- puts "‼️ Swap value of 'Recovered' for 'Active'. API scraper broke."
73
- puts "‼️ So 'Active' is #{state['recovered']} and not #{state['active']}."
83
+ rows << [state['cases'], check_if_positve(state['todayCases']), state['deaths'], check_if_positve(state['todayDeaths']), state['active']]
74
84
 
75
85
  Terminal::Table.new(title: state['state'].upcase, headings: headings, rows: rows)
76
86
  end
@@ -86,7 +96,7 @@ module Kovid
86
96
  rows = []
87
97
 
88
98
  data.each do |country|
89
- rows << [country['country'], country['cases'], country['deaths'], country['recovered']]
99
+ rows << [country['country'].upcase, comma_delimit(country['cases']), comma_delimit(country['deaths']), comma_delimit(country['recovered'])]
90
100
  end
91
101
 
92
102
  Terminal::Table.new(headings: headings, rows: rows)
@@ -109,13 +119,13 @@ module Kovid
109
119
  data.each do |country|
110
120
  rows << [
111
121
  country['country'],
112
- country['cases'],
113
- country['deaths'],
114
- country['recovered'],
115
- country['todayCases'],
116
- country['todayDeaths'],
117
- country['critical'],
118
- country['casesPerOneMillion']
122
+ comma_delimit(country['cases']),
123
+ comma_delimit(country['deaths']),
124
+ comma_delimit(country['recovered']),
125
+ check_if_positve(country['todayCases']),
126
+ check_if_positve(country['todayDeaths']),
127
+ comma_delimit(country['critical']),
128
+ comma_delimit(country['casesPerOneMillion'])
119
129
  ]
120
130
  end
121
131
 
@@ -124,7 +134,13 @@ module Kovid
124
134
 
125
135
  def cases(cases)
126
136
  headings = CASES_DEATHS_RECOVERED
127
- rows = [[cases['cases'], cases['deaths'], cases['recovered']]]
137
+ rows = [
138
+ [
139
+ comma_delimit(cases['cases']),
140
+ comma_delimit(cases['deaths']),
141
+ comma_delimit(cases['recovered'])
142
+ ]
143
+ ]
128
144
 
129
145
  Terminal::Table.new(title: 'Total Number of Incidents Worldwide'.upcase, headings: headings, rows: rows)
130
146
  end
@@ -168,6 +184,14 @@ module Kovid
168
184
  def comma_delimit(number)
169
185
  number.to_s.chars.to_a.reverse.each_slice(3).map(&:join).join(',').reverse
170
186
  end
187
+
188
+ def check_if_positve(num)
189
+ num.to_i.positive? ? "+#{comma_delimit(num)}" : comma_delimit(num).to_s
190
+ end
191
+
192
+ def country_emoji(iso)
193
+ COUNTRY_LETTERS.values_at(*iso.chars).pack('U*')
194
+ end
171
195
  end
172
196
  end
173
197
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kovid
4
- VERSION = '0.2.5'
4
+ VERSION = '0.3.1'
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.2.5
4
+ version: 0.3.1
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-24 00:00:00.000000000 Z
11
+ date: 2020-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -53,19 +53,19 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.3'
55
55
  - !ruby/object:Gem::Dependency
56
- name: colorize
56
+ name: rainbow
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0.8'
61
+ version: '3.0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0.8'
68
+ version: '3.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: pry
71
71
  requirement: !ruby/object:Gem::Requirement