kovid 0.2.7 β 0.3.3
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 +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 +35 -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: 9f04b3f270cae0450368cdffa483d4968dfe6e260a19f4ff244dda25765fba32
|
4
|
+
data.tar.gz: f9381a8141630f18888ec65ced2c352eee1ddd7cd79c131e839fc77e1d4c9255
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b09ebeaa677af45d87d3c37f347caaa9668d95e4c4d67c4462c68143b0dbe1c820faf1e50607acf0460d9acc88abc59958aa8390b1f88396c2ed127dac830fb9
|
7
|
+
data.tar.gz: 7c8a93f91fa8cc64e55cbb2ea055f2d5edc902dd7a5b1d984e0f5a76e967eaa3c239f63fc7f25d13cce4e22cb4e9e288c53ba8752a5bb5ebf41d39f5cdaca5fe
|
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
|
![kovid](https://i.gyazo.com/ab779c3fc838ac279bae5b9d6d10d617.png "Covid data.")
|
59
60
|
|
@@ -81,6 +82,12 @@ To fetch state-specific data run:
|
|
81
82
|
|
82
83
|
![kovid](https://i.gyazo.com/d00b1c5bbb6251cbd517f801c856ba66.png "Covid data.")
|
83
84
|
|
85
|
+
To fetch EU data run:
|
86
|
+
|
87
|
+
`kovid eu`
|
88
|
+
|
89
|
+
![kovid](https://i.gyazo.com/51d2adcb8e9feb0a0fbe38ff9cf4c550.png "Covid data.")
|
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,11 +28,12 @@ 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
|
35
35
|
# TODO: Rafactor this
|
36
|
+
# TODO: Fix emoji
|
36
37
|
end
|
37
38
|
|
38
39
|
def full_country_table(data)
|
@@ -57,15 +58,15 @@ module Kovid
|
|
57
58
|
data['casesPerOneMillion']
|
58
59
|
]
|
59
60
|
|
60
|
-
if iso = data['countryInfo']['iso2']
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
else
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
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
|
69
70
|
# TODO: Rafactor this
|
70
71
|
end
|
71
72
|
|
@@ -95,7 +96,7 @@ module Kovid
|
|
95
96
|
rows = []
|
96
97
|
|
97
98
|
data.each do |country|
|
98
|
-
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'])]
|
99
100
|
end
|
100
101
|
|
101
102
|
Terminal::Table.new(headings: headings, rows: rows)
|
@@ -118,13 +119,13 @@ module Kovid
|
|
118
119
|
data.each do |country|
|
119
120
|
rows << [
|
120
121
|
country['country'],
|
121
|
-
country['cases'],
|
122
|
-
country['deaths'],
|
123
|
-
country['recovered'],
|
122
|
+
comma_delimit(country['cases']),
|
123
|
+
comma_delimit(country['deaths']),
|
124
|
+
comma_delimit(country['recovered']),
|
124
125
|
check_if_positve(country['todayCases']),
|
125
126
|
check_if_positve(country['todayDeaths']),
|
126
|
-
country['critical'],
|
127
|
-
country['casesPerOneMillion']
|
127
|
+
comma_delimit(country['critical']),
|
128
|
+
comma_delimit(country['casesPerOneMillion'])
|
128
129
|
]
|
129
130
|
end
|
130
131
|
|
@@ -133,7 +134,13 @@ module Kovid
|
|
133
134
|
|
134
135
|
def cases(cases)
|
135
136
|
headings = CASES_DEATHS_RECOVERED
|
136
|
-
rows = [
|
137
|
+
rows = [
|
138
|
+
[
|
139
|
+
comma_delimit(cases['cases']),
|
140
|
+
comma_delimit(cases['deaths']),
|
141
|
+
comma_delimit(cases['recovered'])
|
142
|
+
]
|
143
|
+
]
|
137
144
|
|
138
145
|
Terminal::Table.new(title: 'Total Number of Incidents Worldwide'.upcase, headings: headings, rows: rows)
|
139
146
|
end
|
@@ -172,6 +179,16 @@ module Kovid
|
|
172
179
|
Terminal::Table.new(title: country['standardizedCountryName'].upcase, headings: headings, rows: rows)
|
173
180
|
end
|
174
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_green]
|
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: 'EU Aggragation'.upcase, headings: headings, rows: rows)
|
190
|
+
end
|
191
|
+
|
175
192
|
private
|
176
193
|
|
177
194
|
def comma_delimit(number)
|
@@ -179,7 +196,7 @@ module Kovid
|
|
179
196
|
end
|
180
197
|
|
181
198
|
def check_if_positve(num)
|
182
|
-
num.to_i.positive? ? "+#{num}" : num.to_s
|
199
|
+
num.to_i.positive? ? "+#{comma_delimit(num)}" : comma_delimit(num).to_s
|
183
200
|
end
|
184
201
|
|
185
202
|
def country_emoji(iso)
|
data/lib/kovid/version.rb
CHANGED