kovid 0.2.8 β 0.3.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/Gemfile.lock +1 -1
- data/README.md +33 -26
- data/kovid.gemspec +23 -23
- data/lib/kovid.rb +2 -2
- data/lib/kovid/cli.rb +22 -9
- data/lib/kovid/request.rb +19 -2
- data/lib/kovid/tablelize.rb +34 -18
- 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: 7111caf7871b70f2fc2e35c29013e1d3d24b5c130950a82c90786693af22a4c9
|
|
4
|
+
data.tar.gz: 24f9e8bee7b3040a4c181169aa77b8956015db94139d435e95be3339f94facc8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e27a7c550b05e358f7b2250d98d8a9e129aee40acac585a1e31fe41f7a910e1fc1d590b241ed7febe00162dd67a12d27969e810bc3bd7e0b2ab032914174a4a5
|
|
7
|
+
data.tar.gz: 1714bf0e2ab7cd4c928d0700fa146cee5011c4a1858c0b8999f0af206060fb2b73dcb9cb9685d22d7a4389ba10bd574f5dedbb5de7aa34769ad0e160408d4b14
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -1,59 +1,60 @@
|
|
|
1
1
|
# π¦ Kovid
|
|
2
2
|
|
|
3
|
-
[
|
|
4
|
-
|
|
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.
|
|
3
|
+
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 so I thought I'd build this to provide info directly in the terminal. It's where some of us spend time more.
|
|
6
4
|
|
|
7
5
|
Code contribution and ideas welcome.
|
|
8
6
|
|
|
9
7
|
|
|
10
8
|
## βοΈ Installation
|
|
11
9
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
βοΈ Wash your hands with soap and water for at least 20 seconds.
|
|
10
|
+
To install:
|
|
15
11
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
UPDATE often with `gem update kovid`
|
|
12
|
+
* οΈ Wash your hands with soap and water for at least 20 seconds.
|
|
19
13
|
|
|
14
|
+
* Run `gem install kovid`.
|
|
20
15
|
|
|
16
|
+
It's recommended you update often with `gem update kovid`.
|
|
21
17
|
|
|
22
18
|
## βοΈ Usage
|
|
23
19
|
|
|
24
20
|
You can run `kovid --help` to see the full list of available commands.
|
|
25
21
|
|
|
26
|
-
**NOTE:** If you find it irritating to have to type `kovid state STATE`, `covid state STATE` works as well.
|
|
27
|
-
|
|
28
22
|
#### Commands Overview
|
|
29
23
|
π· **Fetching**
|
|
30
|
-
* `kovid check COUNTRY`
|
|
31
|
-
* `kovid check COUNTRY -f` OR `kovid check COUNTRY --full
|
|
24
|
+
* `kovid check COUNTRY` OR `kovid country COUNTRY`.
|
|
25
|
+
* `kovid check COUNTRY -f` OR `kovid check COUNTRY --full`.
|
|
26
|
+
|
|
27
|
+
πͺπΊπͺπΊπͺπΊ
|
|
28
|
+
|
|
29
|
+
You can fetch aggregated EU (all 27 countries combined) data:
|
|
30
|
+
* `kovid eu`.
|
|
31
|
+
|
|
32
|
+
πΊπΈπΊπΈπΊπΈ
|
|
32
33
|
|
|
33
|
-
|
|
34
|
-
* `kovid state STATE` OR `kovid state "STATE
|
|
34
|
+
You can fetch US state-specific data:
|
|
35
|
+
* `kovid state STATE` OR `kovid state "STATE NAME"`.
|
|
35
36
|
|
|
36
37
|
π· **Comparing**
|
|
37
|
-
* `kovid compare
|
|
38
|
-
* `kovid compare
|
|
38
|
+
* `kovid compare FOO BAR` (sorts by cases DESC).
|
|
39
|
+
* `kovid compare FOO BAR -f` OR `kovid compare FOO BAR --full` (sorts by cases DESC).
|
|
39
40
|
|
|
40
|
-
|
|
41
|
+
Where `FOO` and `BAR` are different countries.
|
|
42
|
+
|
|
43
|
+
You can compare as many countries as you want; `kovid compare FOO BAR BAZ` OR `kovid compare FOO BAR BAZ -f`
|
|
41
44
|
|
|
42
45
|
π· **History**
|
|
43
|
-
* `kovid history COUNTRY` (full history)
|
|
44
|
-
* `kovid history COUNTRY N` (history in the last N days)
|
|
46
|
+
* `kovid history COUNTRY` (full history).
|
|
47
|
+
* `kovid history COUNTRY N` (history in the last N days).
|
|
45
48
|
|
|
46
49
|
π· **Total figures**
|
|
47
|
-
* `kovid cases`
|
|
48
|
-
|
|
50
|
+
* `kovid cases` (summary of reported incidents globally).
|
|
49
51
|
|
|
52
|
+
**NOTE:** If you find it irritating to have to type `kovid state STATE`, `covid state STATE` works as well.
|
|
50
53
|
|
|
51
54
|
#### Commands Details
|
|
52
55
|
To fetch basic data on a country run:
|
|
53
56
|
|
|
54
|
-
`kovid check ghana`
|
|
55
|
-
|
|
56
|
-
If the location contains spaces: `kovid check "Diamond Princess"`
|
|
57
|
+
`kovid check ghana`. If the location contains spaces: `kovid check "Diamond Princess"`
|
|
57
58
|
|
|
58
59
|

|
|
59
60
|
|
|
@@ -81,6 +82,12 @@ To fetch state-specific data run:
|
|
|
81
82
|
|
|
82
83
|

|
|
83
84
|
|
|
85
|
+
To fetch EU data run:
|
|
86
|
+
|
|
87
|
+
`kovid eu`
|
|
88
|
+
|
|
89
|
+

|
|
90
|
+
|
|
84
91
|
You can check historical statistics by running
|
|
85
92
|
|
|
86
93
|
`kovid history italy 7` eg:
|
|
@@ -106,7 +113,7 @@ To install this gem onto your local machine, run `bundle exec rake install`.
|
|
|
106
113
|
|
|
107
114
|
## π€² Contributing
|
|
108
115
|
|
|
109
|
-
There are multiple areas in this repo that can be improved or use some refactoring(there's a lot to be
|
|
116
|
+
There are multiple areas in this repo that can be improved or use some refactoring(there's a lot to be refactored in fact!). For that reason, bug reports and pull requests are welcome! This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/siaw23/kovid/blob/master/CODE_OF_CONDUCT.md).
|
|
110
117
|
|
|
111
118
|
|
|
112
119
|
## π License
|
data/kovid.gemspec
CHANGED
|
@@ -14,6 +14,29 @@ Gem::Specification.new do |spec|
|
|
|
14
14
|
|
|
15
15
|
spec.metadata["allowed_push_host"] = "https://rubygems.org/"
|
|
16
16
|
|
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
|
18
|
+
spec.metadata["source_code_uri"] = "https://github.com/siaw23/kovid"
|
|
19
|
+
spec.metadata["changelog_uri"] = "https://github.com/siaw23/kovid"
|
|
20
|
+
|
|
21
|
+
spec.add_dependency "thor", "~> 1.0"
|
|
22
|
+
spec.add_dependency "terminal-table", "~> 1.8"
|
|
23
|
+
spec.add_dependency "typhoeus", "~> 1.3"
|
|
24
|
+
spec.add_dependency "rainbow", "~> 3.0"
|
|
25
|
+
|
|
26
|
+
spec.add_development_dependency "pry"
|
|
27
|
+
spec.add_development_dependency "cucumber"
|
|
28
|
+
spec.add_development_dependency "aruba"
|
|
29
|
+
spec.add_development_dependency "simplecov"
|
|
30
|
+
|
|
31
|
+
# Specify which files should be added to the gem when it is released.
|
|
32
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
33
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
|
34
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
35
|
+
end
|
|
36
|
+
spec.bindir = "exe"
|
|
37
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
38
|
+
spec.require_paths = ["lib"]
|
|
39
|
+
|
|
17
40
|
spec.post_install_message = %q{
|
|
18
41
|
============================================================================
|
|
19
42
|
COVID-19 has devasted the world. But while we're fighting
|
|
@@ -31,27 +54,4 @@ Gem::Specification.new do |spec|
|
|
|
31
54
|
Emmanuel Hayford.
|
|
32
55
|
============================================================================
|
|
33
56
|
}
|
|
34
|
-
|
|
35
|
-
spec.metadata["homepage_uri"] = spec.homepage
|
|
36
|
-
spec.metadata["source_code_uri"] = "https://github.com/siaw23/kovid"
|
|
37
|
-
spec.metadata["changelog_uri"] = "https://github.com/siaw23/kovid"
|
|
38
|
-
|
|
39
|
-
# Specify which files should be added to the gem when it is released.
|
|
40
|
-
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
41
|
-
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
|
42
|
-
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
43
|
-
end
|
|
44
|
-
spec.bindir = "exe"
|
|
45
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
46
|
-
spec.require_paths = ["lib"]
|
|
47
|
-
|
|
48
|
-
spec.add_dependency "thor", "~> 1.0"
|
|
49
|
-
spec.add_dependency "terminal-table", "~> 1.8"
|
|
50
|
-
spec.add_dependency "typhoeus", "~> 1.3"
|
|
51
|
-
spec.add_dependency "rainbow", "~> 3.0"
|
|
52
|
-
|
|
53
|
-
spec.add_development_dependency "pry"
|
|
54
|
-
spec.add_development_dependency "cucumber"
|
|
55
|
-
spec.add_development_dependency "aruba"
|
|
56
|
-
spec.add_development_dependency "simplecov"
|
|
57
57
|
end
|
data/lib/kovid.rb
CHANGED
|
@@ -8,8 +8,8 @@ module Kovid
|
|
|
8
8
|
|
|
9
9
|
module_function
|
|
10
10
|
|
|
11
|
-
def
|
|
12
|
-
|
|
11
|
+
def eu_aggregate
|
|
12
|
+
Kovid::Request.eu_aggregate
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
def country(name)
|
data/lib/kovid/cli.rb
CHANGED
|
@@ -3,26 +3,29 @@
|
|
|
3
3
|
require 'thor'
|
|
4
4
|
require 'kovid'
|
|
5
5
|
|
|
6
|
+
# ["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"]
|
|
7
|
+
|
|
8
|
+
# Czechia has no code
|
|
6
9
|
module Kovid
|
|
7
10
|
class CLI < Thor
|
|
8
11
|
FULL_FLAG = %w[-f --full].freeze
|
|
9
12
|
|
|
10
|
-
desc '
|
|
11
|
-
def
|
|
12
|
-
puts Kovid.
|
|
13
|
+
desc 'check EU', 'Returns aggregated data on the EU.'
|
|
14
|
+
def eu
|
|
15
|
+
puts Kovid.eu_aggregate
|
|
13
16
|
end
|
|
14
17
|
|
|
15
18
|
desc 'check COUNTRY or check "COUNTRY NAME"', 'Returns reported data on provided country. eg: "kovid check "hong kong".'
|
|
16
19
|
method_option :full, aliases: '-f'
|
|
17
20
|
def check(name)
|
|
18
|
-
|
|
19
|
-
puts Kovid.country_full(name)
|
|
20
|
-
else
|
|
21
|
-
puts Kovid.country(name)
|
|
22
|
-
end
|
|
21
|
+
fetch_country_stats(name)
|
|
23
22
|
end
|
|
23
|
+
|
|
24
24
|
desc 'country COUNTRY or country "COUNTRY NAME"', 'Returns reported data on provided country. eg: "kovid country "hong kong".'
|
|
25
|
-
|
|
25
|
+
method_option :full, aliases: '-f'
|
|
26
|
+
def country(name)
|
|
27
|
+
fetch_country_stats(name)
|
|
28
|
+
end
|
|
26
29
|
|
|
27
30
|
desc 'state STATE', 'Return reported data on provided state.'
|
|
28
31
|
def state(state)
|
|
@@ -51,5 +54,15 @@ module Kovid
|
|
|
51
54
|
puts Kovid.history(params.first, nil)
|
|
52
55
|
end
|
|
53
56
|
end
|
|
57
|
+
|
|
58
|
+
private
|
|
59
|
+
|
|
60
|
+
def fetch_country_stats(country)
|
|
61
|
+
if options[:full]
|
|
62
|
+
puts Kovid.country_full(country)
|
|
63
|
+
else
|
|
64
|
+
puts Kovid.country(country)
|
|
65
|
+
end
|
|
66
|
+
end
|
|
54
67
|
end
|
|
55
68
|
end
|
data/lib/kovid/request.rb
CHANGED
|
@@ -9,8 +9,25 @@ module Kovid
|
|
|
9
9
|
class Request
|
|
10
10
|
COUNTRIES_PATH = UriBuilder.new('/countries').url
|
|
11
11
|
STATES_URL = UriBuilder.new('/states').url
|
|
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
|
|
12
13
|
|
|
13
14
|
class << self
|
|
15
|
+
def eu_aggregate
|
|
16
|
+
countries_array = JSON.parse(Typhoeus.get(UriBuilder.new('/countries').url, cache_ttl: 900).response_body)
|
|
17
|
+
|
|
18
|
+
eu_array = countries_array.select do |hash|
|
|
19
|
+
EU_ISOS.include?(hash['countryInfo']['iso2']) || hash['country'] == 'Czechia'
|
|
20
|
+
# Check API later to see if ISO-Alpha-2 code has been added for Czechia
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
first, *rest = eu_array
|
|
24
|
+
eu_data = first.merge(*rest) do |key, left, right|
|
|
25
|
+
left + right unless %w[country countryInfo].include?(key)
|
|
26
|
+
end .compact
|
|
27
|
+
|
|
28
|
+
Kovid::Tablelize.eu_aggregate(eu_data)
|
|
29
|
+
end
|
|
30
|
+
|
|
14
31
|
def by_country(country_name)
|
|
15
32
|
response = fetch_country(country_name)
|
|
16
33
|
|
|
@@ -59,8 +76,8 @@ module Kovid
|
|
|
59
76
|
private
|
|
60
77
|
|
|
61
78
|
def no_case_in(country)
|
|
62
|
-
rows = [[
|
|
63
|
-
Terminal::Table.new
|
|
79
|
+
rows = [["Wrong spelling of location/API has no info on #{country.upcase} at the moment."]]
|
|
80
|
+
Terminal::Table.new title: "You checked: #{country.upcase}", rows: rows
|
|
64
81
|
end
|
|
65
82
|
|
|
66
83
|
def fetch_countries(list)
|
data/lib/kovid/tablelize.rb
CHANGED
|
@@ -28,7 +28,7 @@ module Kovid
|
|
|
28
28
|
rows = [[data['cases'], data['deaths'], data['recovered']]]
|
|
29
29
|
|
|
30
30
|
if iso = data['countryInfo']['iso2']
|
|
31
|
-
Terminal::Table.new(title:
|
|
31
|
+
Terminal::Table.new(title: data['country'].upcase.to_s, headings: headings, rows: rows)
|
|
32
32
|
else
|
|
33
33
|
Terminal::Table.new(title: data['country'].upcase, headings: headings, rows: rows)
|
|
34
34
|
end
|
|
@@ -58,15 +58,15 @@ module Kovid
|
|
|
58
58
|
data['casesPerOneMillion']
|
|
59
59
|
]
|
|
60
60
|
|
|
61
|
-
if iso = data['countryInfo']['iso2']
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
else
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
end
|
|
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
70
|
# TODO: Rafactor this
|
|
71
71
|
end
|
|
72
72
|
|
|
@@ -96,7 +96,7 @@ module Kovid
|
|
|
96
96
|
rows = []
|
|
97
97
|
|
|
98
98
|
data.each do |country|
|
|
99
|
-
rows << [country['country'].upcase, country['cases'], country['deaths'], country['recovered']]
|
|
99
|
+
rows << [country['country'].upcase, comma_delimit(country['cases']), comma_delimit(country['deaths']), comma_delimit(country['recovered'])]
|
|
100
100
|
end
|
|
101
101
|
|
|
102
102
|
Terminal::Table.new(headings: headings, rows: rows)
|
|
@@ -119,13 +119,13 @@ module Kovid
|
|
|
119
119
|
data.each do |country|
|
|
120
120
|
rows << [
|
|
121
121
|
country['country'],
|
|
122
|
-
country['cases'],
|
|
123
|
-
country['deaths'],
|
|
124
|
-
country['recovered'],
|
|
122
|
+
comma_delimit(country['cases']),
|
|
123
|
+
comma_delimit(country['deaths']),
|
|
124
|
+
comma_delimit(country['recovered']),
|
|
125
125
|
check_if_positve(country['todayCases']),
|
|
126
126
|
check_if_positve(country['todayDeaths']),
|
|
127
|
-
country['critical'],
|
|
128
|
-
country['casesPerOneMillion']
|
|
127
|
+
comma_delimit(country['critical']),
|
|
128
|
+
comma_delimit(country['casesPerOneMillion'])
|
|
129
129
|
]
|
|
130
130
|
end
|
|
131
131
|
|
|
@@ -134,7 +134,13 @@ module Kovid
|
|
|
134
134
|
|
|
135
135
|
def cases(cases)
|
|
136
136
|
headings = CASES_DEATHS_RECOVERED
|
|
137
|
-
rows = [
|
|
137
|
+
rows = [
|
|
138
|
+
[
|
|
139
|
+
comma_delimit(cases['cases']),
|
|
140
|
+
comma_delimit(cases['deaths']),
|
|
141
|
+
comma_delimit(cases['recovered'])
|
|
142
|
+
]
|
|
143
|
+
]
|
|
138
144
|
|
|
139
145
|
Terminal::Table.new(title: 'Total Number of Incidents Worldwide'.upcase, headings: headings, rows: rows)
|
|
140
146
|
end
|
|
@@ -173,6 +179,16 @@ module Kovid
|
|
|
173
179
|
Terminal::Table.new(title: country['standardizedCountryName'].upcase, headings: headings, rows: rows)
|
|
174
180
|
end
|
|
175
181
|
|
|
182
|
+
def eu_aggregate(eu_data)
|
|
183
|
+
headings = ['Cases'.paint_white, 'Cases Today'.paint_white, 'Deaths'.paint_red, 'Deaths Today'.paint_red, 'Recovered'.paint_green, 'Active'.paint_yellow, 'Critical'.paint_red]
|
|
184
|
+
|
|
185
|
+
rows = []
|
|
186
|
+
|
|
187
|
+
rows << [comma_delimit(eu_data['cases']), check_if_positve(eu_data['todayCases']), comma_delimit(eu_data['deaths']), check_if_positve(eu_data['todayDeaths']), comma_delimit(eu_data['recovered']), comma_delimit(eu_data['active']), comma_delimit(eu_data['critical'])]
|
|
188
|
+
|
|
189
|
+
Terminal::Table.new(title: 'Aggregated EU Data'.upcase, headings: headings, rows: rows)
|
|
190
|
+
end
|
|
191
|
+
|
|
176
192
|
private
|
|
177
193
|
|
|
178
194
|
def comma_delimit(number)
|
|
@@ -180,7 +196,7 @@ module Kovid
|
|
|
180
196
|
end
|
|
181
197
|
|
|
182
198
|
def check_if_positve(num)
|
|
183
|
-
num.to_i.positive? ? "+#{num}" : num.to_s
|
|
199
|
+
num.to_i.positive? ? "+#{comma_delimit(num)}" : comma_delimit(num).to_s
|
|
184
200
|
end
|
|
185
201
|
|
|
186
202
|
def country_emoji(iso)
|
data/lib/kovid/version.rb
CHANGED