kovid 0.6.9 → 0.6.14
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 +11 -11
- data/README.md +32 -0
- data/lib/kovid.rb +6 -2
- data/lib/kovid/cli.rb +33 -3
- data/lib/kovid/constants.rb +18 -14
- data/lib/kovid/helpers.rb +0 -6
- data/lib/kovid/historians.rb +33 -28
- data/lib/kovid/request.rb +76 -58
- data/lib/kovid/tablelize.rb +63 -5
- data/lib/kovid/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2896f04560ac519045555f79fc0d8cdcbcee7ed9069aecd1ebdbcba181584927
|
|
4
|
+
data.tar.gz: fe15af9091b1a03ae8ac6a78e712c5a7dc7dd1a7b433e45b9c6bdad05c709f22
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9a4260377fa1d38f2b9dd9f7b94bdcf3527e437f2c89e15d15d1a0b87df11a09934baa56a6d8b13f1e1a588b0590b4a1646f7ca6f9c96a141f1b2178054bc358
|
|
7
|
+
data.tar.gz: c9c313cf8982980845c5d73d5da9e9d9cab82738825762bbceb3a07e511f7ccae1d12516cadd80bfb86fa88c8a2dd4b58615db396a0ba901d7fa94fbddcd21c7
|
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
kovid (0.6.
|
|
4
|
+
kovid (0.6.13)
|
|
5
5
|
carmen (~> 1.1.3)
|
|
6
6
|
rainbow (~> 3.0)
|
|
7
7
|
terminal-table (~> 1.8)
|
|
@@ -11,12 +11,12 @@ PATH
|
|
|
11
11
|
GEM
|
|
12
12
|
remote: https://rubygems.org/
|
|
13
13
|
specs:
|
|
14
|
-
activesupport (6.0.
|
|
14
|
+
activesupport (6.0.3.1)
|
|
15
15
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
16
16
|
i18n (>= 0.7, < 2)
|
|
17
17
|
minitest (~> 5.1)
|
|
18
18
|
tzinfo (~> 1.1)
|
|
19
|
-
zeitwerk (~> 2.2)
|
|
19
|
+
zeitwerk (~> 2.2, >= 2.2.2)
|
|
20
20
|
carmen (1.1.3)
|
|
21
21
|
activesupport (>= 3.0.0)
|
|
22
22
|
concurrent-ruby (1.1.6)
|
|
@@ -24,25 +24,25 @@ GEM
|
|
|
24
24
|
docile (1.3.2)
|
|
25
25
|
ethon (0.12.0)
|
|
26
26
|
ffi (>= 1.3.0)
|
|
27
|
-
ffi (1.
|
|
28
|
-
i18n (1.8.
|
|
27
|
+
ffi (1.13.0)
|
|
28
|
+
i18n (1.8.3)
|
|
29
29
|
concurrent-ruby (~> 1.0)
|
|
30
|
-
minitest (5.14.
|
|
30
|
+
minitest (5.14.1)
|
|
31
31
|
rainbow (3.0.0)
|
|
32
32
|
rake (12.3.3)
|
|
33
33
|
rspec (3.9.0)
|
|
34
34
|
rspec-core (~> 3.9.0)
|
|
35
35
|
rspec-expectations (~> 3.9.0)
|
|
36
36
|
rspec-mocks (~> 3.9.0)
|
|
37
|
-
rspec-core (3.9.
|
|
38
|
-
rspec-support (~> 3.9.
|
|
39
|
-
rspec-expectations (3.9.
|
|
37
|
+
rspec-core (3.9.2)
|
|
38
|
+
rspec-support (~> 3.9.3)
|
|
39
|
+
rspec-expectations (3.9.2)
|
|
40
40
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
41
41
|
rspec-support (~> 3.9.0)
|
|
42
42
|
rspec-mocks (3.9.1)
|
|
43
43
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
44
44
|
rspec-support (~> 3.9.0)
|
|
45
|
-
rspec-support (3.9.
|
|
45
|
+
rspec-support (3.9.3)
|
|
46
46
|
simplecov (0.18.5)
|
|
47
47
|
docile (~> 1.1)
|
|
48
48
|
simplecov-html (~> 0.11)
|
|
@@ -51,7 +51,7 @@ GEM
|
|
|
51
51
|
unicode-display_width (~> 1.1, >= 1.1.1)
|
|
52
52
|
thor (1.0.1)
|
|
53
53
|
thread_safe (0.3.6)
|
|
54
|
-
typhoeus (1.
|
|
54
|
+
typhoeus (1.4.0)
|
|
55
55
|
ethon (>= 0.9.0)
|
|
56
56
|
tzinfo (1.2.7)
|
|
57
57
|
thread_safe (~> 0.1)
|
data/README.md
CHANGED
|
@@ -76,6 +76,12 @@ ___
|
|
|
76
76
|
* `kovid history COUNTRY N` (history in the last N days).
|
|
77
77
|
* `kovid history STATE --usa`
|
|
78
78
|
___
|
|
79
|
+
😷 **Top N (by cases/deaths for countries and US States)**
|
|
80
|
+
* `kovid top N` (top N countries in number of cases).
|
|
81
|
+
* `kovid top N -d` OR `kovid top N --deaths` (top N countries in number of deaths).
|
|
82
|
+
* `kovid top N --states` (top N US states in number of cases).
|
|
83
|
+
* `kovid top N --states -d` (top N countries in number of deaths).
|
|
84
|
+
___
|
|
79
85
|
|
|
80
86
|
**NOTE:** If you find it irritating to have to type `kovid state STATE`, `covid state STATE` works as well.
|
|
81
87
|
|
|
@@ -139,6 +145,32 @@ To check for total figures:
|
|
|
139
145
|
|
|
140
146
|

|
|
141
147
|
|
|
148
|
+
To fetch top 5 countries in number of cases or deaths:
|
|
149
|
+
|
|
150
|
+
`kovid top`
|
|
151
|
+
|
|
152
|
+

|
|
153
|
+
|
|
154
|
+
`kovid top --deaths` OR `kovid top -d`
|
|
155
|
+
|
|
156
|
+

|
|
157
|
+
|
|
158
|
+
It is also possible to fetch top US states in number of cases or deaths:
|
|
159
|
+
|
|
160
|
+
`kovid top --states`
|
|
161
|
+
|
|
162
|
+

|
|
163
|
+
|
|
164
|
+
`kovid top --states --deaths` OR `kovid top --states -d`
|
|
165
|
+
|
|
166
|
+

|
|
167
|
+
|
|
168
|
+
To fetch more number of countries or US states you can pass N. eg:
|
|
169
|
+
|
|
170
|
+
`kovid top 10`
|
|
171
|
+
|
|
172
|
+

|
|
173
|
+
|
|
142
174
|
## 👩🏾🔬 Experimental Feature
|
|
143
175
|
|
|
144
176
|
`kovid histogram italy 3.20` tries to build a histogram on number of cases. In the example here `3.20` is date in the format of `M.YY`. If you can please play with it and report issues on how this could be improved.
|
data/lib/kovid.rb
CHANGED
|
@@ -68,15 +68,19 @@ module Kovid
|
|
|
68
68
|
Kovid::Request.cases
|
|
69
69
|
end
|
|
70
70
|
|
|
71
|
-
def history(country, days=30)
|
|
71
|
+
def history(country, days = 30)
|
|
72
72
|
Kovid::Request.history(country, days)
|
|
73
73
|
end
|
|
74
74
|
|
|
75
|
-
def history_us_state(state, days=30)
|
|
75
|
+
def history_us_state(state, days = 30)
|
|
76
76
|
Kovid::Request.history_us_state(state, days)
|
|
77
77
|
end
|
|
78
78
|
|
|
79
79
|
def histogram(country, date)
|
|
80
80
|
Kovid::Request.histogram(country, date)
|
|
81
81
|
end
|
|
82
|
+
|
|
83
|
+
def top(count, options = { location: :countries, incident: :cases })
|
|
84
|
+
Kovid::Request.top(count, options)
|
|
85
|
+
end
|
|
82
86
|
end
|
data/lib/kovid/cli.rb
CHANGED
|
@@ -78,8 +78,8 @@ module Kovid
|
|
|
78
78
|
desc 'history COUNTRY or history COUNTRY N or' \
|
|
79
79
|
'history STATE --usa',
|
|
80
80
|
'Return history of incidents of COUNTRY|STATE (in the last N days)'
|
|
81
|
-
option :usa, :
|
|
82
|
-
def history(location, days=30)
|
|
81
|
+
option :usa, type: :boolean
|
|
82
|
+
def history(location, days = 30)
|
|
83
83
|
if options[:usa]
|
|
84
84
|
puts Kovid.history_us_state(location, days)
|
|
85
85
|
else
|
|
@@ -133,6 +133,20 @@ module Kovid
|
|
|
133
133
|
end
|
|
134
134
|
end
|
|
135
135
|
|
|
136
|
+
desc 'top N',
|
|
137
|
+
'Returns top N countries or states in an incident (number of cases or
|
|
138
|
+
deaths).'
|
|
139
|
+
method_option :countries
|
|
140
|
+
method_option :states
|
|
141
|
+
method_option :cases, aliases: '-c'
|
|
142
|
+
method_option :deaths, aliases: '-d'
|
|
143
|
+
def top(count = 5)
|
|
144
|
+
count = count.to_i
|
|
145
|
+
count = 5 if count.zero?
|
|
146
|
+
puts Kovid.top(count, prepare_top_params(options))
|
|
147
|
+
data_source
|
|
148
|
+
end
|
|
149
|
+
|
|
136
150
|
private
|
|
137
151
|
|
|
138
152
|
def fetch_country_stats(country)
|
|
@@ -147,10 +161,26 @@ module Kovid
|
|
|
147
161
|
source = <<~TEXT
|
|
148
162
|
#{Time.now}
|
|
149
163
|
Sources:
|
|
164
|
+
* worldometers.info/coronavirus
|
|
150
165
|
* Johns Hopkins University
|
|
151
|
-
* https://www.worldometers.info/coronavirus
|
|
152
166
|
TEXT
|
|
153
167
|
puts source
|
|
154
168
|
end
|
|
169
|
+
|
|
170
|
+
def prepare_top_params(options)
|
|
171
|
+
params = {
|
|
172
|
+
location: :countries,
|
|
173
|
+
incident: :cases
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if !options[:states].nil? && options[:countries].nil?
|
|
177
|
+
params[:location] = :states
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
if !options[:deaths].nil? && options[:cases].nil?
|
|
181
|
+
params[:incident] = :deaths
|
|
182
|
+
end
|
|
183
|
+
params
|
|
184
|
+
end
|
|
155
185
|
end
|
|
156
186
|
end
|
data/lib/kovid/constants.rb
CHANGED
|
@@ -13,7 +13,9 @@ module Kovid
|
|
|
13
13
|
'Cases Today'.paint_white,
|
|
14
14
|
'Deaths'.paint_red,
|
|
15
15
|
'Deaths Today'.paint_red,
|
|
16
|
-
'
|
|
16
|
+
'Active'.paint_yellow,
|
|
17
|
+
'Recovered'.paint_green,
|
|
18
|
+
'Tests'.paint_white
|
|
17
19
|
].freeze
|
|
18
20
|
|
|
19
21
|
DATE_CASES_DEATHS_RECOVERED = [
|
|
@@ -56,15 +58,18 @@ module Kovid
|
|
|
56
58
|
'Cases Today'.paint_white,
|
|
57
59
|
'Deaths'.paint_red,
|
|
58
60
|
'Deaths Today'.paint_red,
|
|
59
|
-
'Recovered'.paint_green
|
|
61
|
+
'Recovered'.paint_green,
|
|
62
|
+
'Tests'.paint_white
|
|
60
63
|
].freeze
|
|
61
64
|
|
|
62
65
|
FULL_COUNTRY_TABLE_HEADINGS = [
|
|
63
66
|
'Cases'.paint_white,
|
|
64
|
-
'Deaths'.paint_red,
|
|
65
|
-
'Recovered'.paint_green,
|
|
66
67
|
'Cases Today'.paint_white,
|
|
68
|
+
'Deaths'.paint_red,
|
|
67
69
|
'Deaths Today'.paint_red,
|
|
70
|
+
'Active'.paint_yellow,
|
|
71
|
+
'Recovered'.paint_green,
|
|
72
|
+
'Tests'.paint_white,
|
|
68
73
|
'Critical'.paint_yellow,
|
|
69
74
|
'Cases/Million'.paint_white
|
|
70
75
|
].freeze
|
|
@@ -80,7 +85,8 @@ module Kovid
|
|
|
80
85
|
'Cases Today'.paint_white,
|
|
81
86
|
'Deaths'.paint_red,
|
|
82
87
|
'Deaths Today'.paint_red,
|
|
83
|
-
'Active'.paint_yellow
|
|
88
|
+
'Active'.paint_yellow,
|
|
89
|
+
'Tests'.paint_white
|
|
84
90
|
].freeze
|
|
85
91
|
|
|
86
92
|
COMPARE_STATES_HEADINGS = [
|
|
@@ -99,18 +105,16 @@ module Kovid
|
|
|
99
105
|
'Recovered'.paint_green
|
|
100
106
|
].freeze
|
|
101
107
|
|
|
102
|
-
|
|
103
|
-
'------------',
|
|
104
|
-
'------------',
|
|
108
|
+
FOOTER_LINE_COLUMN = [
|
|
105
109
|
'------------'
|
|
106
110
|
].freeze
|
|
107
111
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
112
|
+
FOOTER_LINE_THREE_COLUMNS = FOOTER_LINE_COLUMN * 3
|
|
113
|
+
|
|
114
|
+
FOOTER_LINE_FOUR_COLUMNS = FOOTER_LINE_COLUMN * 4
|
|
115
|
+
|
|
116
|
+
# Add footer if rows exceed this number
|
|
117
|
+
ADD_FOOTER_SIZE = 10
|
|
114
118
|
|
|
115
119
|
COUNTRY_LETTERS = 'A'.upto('Z').with_index(127_462).to_h.freeze
|
|
116
120
|
|
data/lib/kovid/helpers.rb
CHANGED
|
@@ -25,12 +25,6 @@ module Kovid
|
|
|
25
25
|
num.to_i.positive? ? "+#{comma_delimit(num)}" : comma_delimit(num).to_s
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
-
def format_country_history_numbers(load)
|
|
29
|
-
load['timeline'].values.map(&:values).transpose.each do |data|
|
|
30
|
-
data.map! { |number| Kovid.comma_delimit(number) }
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
|
|
34
28
|
def lookup_us_state(state)
|
|
35
29
|
us = Carmen::Country.coded('USA')
|
|
36
30
|
lookup = us.subregions.coded(state) || us.subregions.named(state)
|
data/lib/kovid/historians.rb
CHANGED
|
@@ -5,42 +5,32 @@ module Kovid
|
|
|
5
5
|
include Constants
|
|
6
6
|
include AsciiCharts
|
|
7
7
|
|
|
8
|
-
def history(
|
|
9
|
-
rows =
|
|
8
|
+
def history(data, days)
|
|
9
|
+
rows = history_rows(data, days)
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if days.to_i >= 30
|
|
15
|
-
stats = stats.reject { |stat| stat[0].to_i.zero? && stat[1].to_i.zero? }
|
|
16
|
-
dates = dates.last(stats.count)
|
|
11
|
+
if rows.size > ADD_FOOTER_SIZE
|
|
12
|
+
rows << FOOTER_LINE_FOUR_COLUMNS
|
|
13
|
+
rows << DATE_CASES_DEATHS_RECOVERED
|
|
17
14
|
end
|
|
18
15
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
rows
|
|
23
|
-
|
|
16
|
+
Terminal::Table.new(
|
|
17
|
+
title: data['country'].try(:upcase),
|
|
18
|
+
headings: DATE_CASES_DEATHS_RECOVERED,
|
|
19
|
+
rows: rows
|
|
20
|
+
)
|
|
21
|
+
end
|
|
24
22
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
title = location['country'].try(:upcase)
|
|
28
|
-
col_format = DATE_CASES_DEATHS_RECOVERED
|
|
29
|
-
footer = FOOTER_LINE_FOUR_COLUMNS
|
|
30
|
-
else
|
|
31
|
-
title = location['state'].try(:upcase)
|
|
32
|
-
col_format = DATE_CASES_DEATHS
|
|
33
|
-
footer = FOOTER_LINE_THREE_COLUMNS
|
|
34
|
-
end
|
|
23
|
+
def history_us_state(data, days)
|
|
24
|
+
rows = history_rows(data, days)
|
|
35
25
|
|
|
36
|
-
if
|
|
37
|
-
rows <<
|
|
38
|
-
rows <<
|
|
26
|
+
if rows.size > ADD_FOOTER_SIZE
|
|
27
|
+
rows << FOOTER_LINE_THREE_COLUMNS
|
|
28
|
+
rows << DATE_CASES_DEATHS
|
|
39
29
|
end
|
|
40
30
|
|
|
41
31
|
Terminal::Table.new(
|
|
42
|
-
title:
|
|
43
|
-
headings:
|
|
32
|
+
title: data['state'].try(:upcase),
|
|
33
|
+
headings: DATE_CASES_DEATHS,
|
|
44
34
|
rows: rows
|
|
45
35
|
)
|
|
46
36
|
end
|
|
@@ -106,5 +96,20 @@ module Kovid
|
|
|
106
96
|
AsciiCharts::Cartesian.new(data, bar: true, hide_zero: true).draw
|
|
107
97
|
end
|
|
108
98
|
end
|
|
99
|
+
|
|
100
|
+
private
|
|
101
|
+
|
|
102
|
+
def history_rows(data, days)
|
|
103
|
+
data['timeline']['cases'].map do |date, cases|
|
|
104
|
+
formatted_date = Kovid.dateman(date)
|
|
105
|
+
cases = Kovid.comma_delimit(cases)
|
|
106
|
+
deaths = Kovid.comma_delimit(data['timeline']['deaths'][date])
|
|
107
|
+
recovered = Kovid.comma_delimit(data['timeline']['recovered'][date]) if data['timeline'].has_key? 'recovered'
|
|
108
|
+
|
|
109
|
+
row = [formatted_date, cases, deaths]
|
|
110
|
+
row << recovered unless recovered.nil?
|
|
111
|
+
row
|
|
112
|
+
end.last(days.to_i)
|
|
113
|
+
end
|
|
109
114
|
end
|
|
110
115
|
end
|
data/lib/kovid/request.rb
CHANGED
|
@@ -8,28 +8,28 @@ require_relative 'uri_builder'
|
|
|
8
8
|
|
|
9
9
|
module Kovid
|
|
10
10
|
class Request
|
|
11
|
-
COUNTRIES_PATH
|
|
12
|
-
STATES_URL
|
|
13
|
-
JHUCSSE_URL
|
|
14
|
-
HISTORICAL_URL
|
|
15
|
-
HISTORICAL_US_URL
|
|
16
|
-
|
|
17
|
-
SERVER_DOWN
|
|
18
|
-
|
|
19
|
-
EU_ISOS
|
|
20
|
-
|
|
21
|
-
EUROPE_ISOS
|
|
22
|
-
|
|
23
|
-
AFRICA_ISOS
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
SOUTH_AMERICA_ISOS
|
|
28
|
-
|
|
29
|
-
ASIA_ISOS
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
11
|
+
COUNTRIES_PATH = UriBuilder.new('/v2/countries').url
|
|
12
|
+
STATES_URL = UriBuilder.new('/v2/states').url
|
|
13
|
+
JHUCSSE_URL = UriBuilder.new('/v2/jhucsse').url
|
|
14
|
+
HISTORICAL_URL = UriBuilder.new('/v2/historical').url
|
|
15
|
+
HISTORICAL_US_URL = UriBuilder.new('/v2/historical/usacounties').url
|
|
16
|
+
|
|
17
|
+
SERVER_DOWN = 'Server overwhelmed. Please try again in a moment.'
|
|
18
|
+
|
|
19
|
+
EU_ISOS = %w[AT BE BG CY CZ DE DK EE ES FI FR GR HR HU IE IT LT \
|
|
20
|
+
LU LV MT NL PL PT RO SE SI SK].freeze
|
|
21
|
+
EUROPE_ISOS = EU_ISOS + %w[GB IS NO CH MC AD SM VA BA RS ME MK AL \
|
|
22
|
+
BY UA RU MD].freeze
|
|
23
|
+
AFRICA_ISOS = %w[DZ AO BJ BW BF BI CM CV CF TD KM CD CG CI DJ EG \
|
|
24
|
+
GQ ER SZ ET GA GM GH GN GW KE LS LR LY MG MW ML \
|
|
25
|
+
MR MU MA MZ NA NE NG RW ST SN SC SL SO ZA SS SD \
|
|
26
|
+
TZ TG TN UG ZM ZW EH].freeze
|
|
27
|
+
SOUTH_AMERICA_ISOS = %w[AR BO BV BR CL CO EC FK GF GY PY PE GS SR \
|
|
28
|
+
UY VE].freeze
|
|
29
|
+
ASIA_ISOS = %w[AE AF AM AZ BD BH BN BT CC CN CX GE HK ID IL IN \
|
|
30
|
+
IQ IR JO JP KG KH KP KR KW KZ LA LB LK MM MN MO \
|
|
31
|
+
MY NP OM PH PK PS QA SA SG SY TH TJ TL TM TR TW \
|
|
32
|
+
UZ VN YE].freeze
|
|
33
33
|
|
|
34
34
|
class << self
|
|
35
35
|
def eu_aggregate
|
|
@@ -113,6 +113,7 @@ module Kovid
|
|
|
113
113
|
|
|
114
114
|
def state(state)
|
|
115
115
|
response = fetch_state(Kovid.lookup_us_state(state))
|
|
116
|
+
|
|
116
117
|
if response.nil?
|
|
117
118
|
not_found(state)
|
|
118
119
|
else
|
|
@@ -161,17 +162,11 @@ module Kovid
|
|
|
161
162
|
end
|
|
162
163
|
|
|
163
164
|
def history(country, days)
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
response = JSON.parse(
|
|
167
|
-
Typhoeus.get(
|
|
168
|
-
history_path + "/#{country}", cache_ttl: 900
|
|
169
|
-
).response_body
|
|
170
|
-
)
|
|
165
|
+
response = fetch_history(country)
|
|
171
166
|
|
|
172
167
|
if response.key?('message')
|
|
173
168
|
not_found(country) do |c|
|
|
174
|
-
"Could not find cases for #{c}.\nIf searching United States, add --usa option"
|
|
169
|
+
"Could not find cases for #{c}.\nIf searching United States, add --usa option"
|
|
175
170
|
end
|
|
176
171
|
else
|
|
177
172
|
Kovid::Tablelize.history(response, days)
|
|
@@ -181,16 +176,10 @@ module Kovid
|
|
|
181
176
|
end
|
|
182
177
|
|
|
183
178
|
def history_us_state(state, days)
|
|
184
|
-
|
|
185
|
-
|
|
179
|
+
state = Kovid.lookup_us_state(state).downcase
|
|
180
|
+
response = fetch_us_history(state)
|
|
186
181
|
|
|
187
|
-
response
|
|
188
|
-
Typhoeus.get(
|
|
189
|
-
history_path + "/#{state}", cache_ttl: 900
|
|
190
|
-
).response_body
|
|
191
|
-
)
|
|
192
|
-
|
|
193
|
-
if response.respond_to?(:key?) and response.key?('message')
|
|
182
|
+
if response.respond_to?(:key?) && response.key?('message')
|
|
194
183
|
return not_found(state)
|
|
195
184
|
end
|
|
196
185
|
|
|
@@ -200,28 +189,39 @@ module Kovid
|
|
|
200
189
|
cases = usacounties_aggregator(response, 'cases')
|
|
201
190
|
deaths = usacounties_aggregator(response, 'deaths')
|
|
202
191
|
|
|
203
|
-
# normalize data so we can call Kovid::Tablelize.history on US State data
|
|
204
192
|
response = {
|
|
205
|
-
|
|
206
|
-
|
|
193
|
+
'state' => state,
|
|
194
|
+
'timeline' => { 'cases' => cases, 'deaths' => deaths }
|
|
207
195
|
}
|
|
208
196
|
|
|
209
|
-
Kovid::Tablelize.
|
|
197
|
+
Kovid::Tablelize.history_us_state(response, days)
|
|
210
198
|
rescue JSON::ParserError
|
|
211
|
-
|
|
199
|
+
puts SERVER_DOWN
|
|
212
200
|
end
|
|
213
201
|
|
|
214
202
|
def histogram(country, date)
|
|
215
|
-
history_path = UriBuilder.new('/v2/historical').url
|
|
216
203
|
response = JSON.parse(
|
|
217
204
|
Typhoeus.get(
|
|
218
|
-
|
|
205
|
+
HISTORICAL_URL + "/#{country}", cache_ttl: 900
|
|
219
206
|
).response_body
|
|
220
207
|
)
|
|
221
208
|
|
|
222
209
|
Kovid::Tablelize.histogram(response, date)
|
|
223
210
|
end
|
|
224
211
|
|
|
212
|
+
def top(count, options)
|
|
213
|
+
response = JSON.parse(
|
|
214
|
+
Typhoeus.get(
|
|
215
|
+
top_url(options[:location]) +
|
|
216
|
+
"?sort=#{options[:incident]}",
|
|
217
|
+
cache_ttl: 900
|
|
218
|
+
).response_body
|
|
219
|
+
)
|
|
220
|
+
|
|
221
|
+
Kovid::Tablelize.top(response.first(count),
|
|
222
|
+
options.merge({ count: count }))
|
|
223
|
+
end
|
|
224
|
+
|
|
225
225
|
def capitalize_words(string)
|
|
226
226
|
string.split.map(&:capitalize).join(' ')
|
|
227
227
|
end
|
|
@@ -232,11 +232,11 @@ module Kovid
|
|
|
232
232
|
rows = []
|
|
233
233
|
default_warning = "Wrong spelling/No reported cases on #{location.upcase}."
|
|
234
234
|
|
|
235
|
-
if block_given?
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
235
|
+
rows << if block_given?
|
|
236
|
+
[yield(location)]
|
|
237
|
+
else
|
|
238
|
+
[default_warning]
|
|
239
|
+
end
|
|
240
240
|
|
|
241
241
|
Terminal::Table.new title: "You checked: #{location.upcase}", rows: rows
|
|
242
242
|
end
|
|
@@ -298,6 +298,22 @@ module Kovid
|
|
|
298
298
|
end.first
|
|
299
299
|
end
|
|
300
300
|
|
|
301
|
+
def fetch_history(country)
|
|
302
|
+
JSON.parse(
|
|
303
|
+
Typhoeus.get(
|
|
304
|
+
HISTORICAL_URL + "/#{country}", cache_ttl: 900
|
|
305
|
+
).response_body
|
|
306
|
+
)
|
|
307
|
+
end
|
|
308
|
+
|
|
309
|
+
def fetch_us_history(state)
|
|
310
|
+
JSON.parse(
|
|
311
|
+
Typhoeus.get(
|
|
312
|
+
HISTORICAL_US_URL + "/#{state}", cache_ttl: 900
|
|
313
|
+
).response_body
|
|
314
|
+
)
|
|
315
|
+
end
|
|
316
|
+
|
|
301
317
|
def aggregator(isos, meth)
|
|
302
318
|
countries_array = JSON.parse(countries_request)
|
|
303
319
|
country_array = countries_array.select do |hash|
|
|
@@ -311,9 +327,7 @@ module Kovid
|
|
|
311
327
|
end
|
|
312
328
|
|
|
313
329
|
def countries_request
|
|
314
|
-
Typhoeus.get(
|
|
315
|
-
UriBuilder.new('/v2/countries').url, cache_ttl: 900
|
|
316
|
-
).response_body
|
|
330
|
+
Typhoeus.get(COUNTRIES_PATH, cache_ttl: 900).response_body
|
|
317
331
|
end
|
|
318
332
|
|
|
319
333
|
def countries_aggregator(country_array)
|
|
@@ -327,15 +341,19 @@ module Kovid
|
|
|
327
341
|
end.compact
|
|
328
342
|
end
|
|
329
343
|
|
|
330
|
-
def usacounties_aggregator(data, key=nil)
|
|
331
|
-
data.inject({}) do |base,other|
|
|
332
|
-
base.merge(other['timeline'][key]) do |
|
|
333
|
-
l ||= 0
|
|
344
|
+
def usacounties_aggregator(data, key = nil)
|
|
345
|
+
data.inject({}) do |base, other|
|
|
346
|
+
base.merge(other['timeline'][key]) do |_k, l, r|
|
|
334
347
|
l ||= 0
|
|
348
|
+
r ||= 0
|
|
335
349
|
l + r
|
|
336
350
|
end
|
|
337
351
|
end.compact
|
|
338
352
|
end
|
|
353
|
+
|
|
354
|
+
def top_url(location)
|
|
355
|
+
location == :countries ? COUNTRIES_PATH : STATES_URL
|
|
356
|
+
end
|
|
339
357
|
end
|
|
340
358
|
end
|
|
341
359
|
end
|
data/lib/kovid/tablelize.rb
CHANGED
|
@@ -39,7 +39,7 @@ module Kovid
|
|
|
39
39
|
Terminal::Table.new(
|
|
40
40
|
title: state['state'].upcase,
|
|
41
41
|
headings: FULL_STATE_TABLE_HEADINGS,
|
|
42
|
-
rows: [
|
|
42
|
+
rows: [state_row(state)]
|
|
43
43
|
)
|
|
44
44
|
end
|
|
45
45
|
|
|
@@ -96,6 +96,22 @@ module Kovid
|
|
|
96
96
|
)
|
|
97
97
|
end
|
|
98
98
|
|
|
99
|
+
def top(data, options)
|
|
100
|
+
headings = top_heading(options)
|
|
101
|
+
rows = data.map { |location| top_row(location, options) }
|
|
102
|
+
|
|
103
|
+
if options[:count] > 10
|
|
104
|
+
rows << FOOTER_LINE_COLUMN * headings.count
|
|
105
|
+
rows << headings
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
Terminal::Table.new(
|
|
109
|
+
title: top_title(options),
|
|
110
|
+
headings: headings,
|
|
111
|
+
rows: rows
|
|
112
|
+
)
|
|
113
|
+
end
|
|
114
|
+
|
|
99
115
|
private
|
|
100
116
|
|
|
101
117
|
def country_title(data)
|
|
@@ -120,29 +136,44 @@ module Kovid
|
|
|
120
136
|
]
|
|
121
137
|
end
|
|
122
138
|
|
|
123
|
-
# Also works for state
|
|
124
139
|
def country_row(data)
|
|
125
140
|
[
|
|
126
141
|
Kovid.comma_delimit(data['cases']),
|
|
127
142
|
Kovid.add_plus_sign(data['todayCases']),
|
|
128
143
|
Kovid.comma_delimit(data['deaths']),
|
|
129
144
|
Kovid.add_plus_sign(data['todayDeaths']),
|
|
130
|
-
Kovid.comma_delimit(data['
|
|
145
|
+
Kovid.comma_delimit(data['active']),
|
|
146
|
+
Kovid.comma_delimit(data['recovered']),
|
|
147
|
+
Kovid.comma_delimit(data['tests'])
|
|
131
148
|
]
|
|
132
149
|
end
|
|
133
150
|
|
|
134
151
|
def full_country_row(data)
|
|
135
152
|
[
|
|
136
153
|
Kovid.comma_delimit(data['cases']),
|
|
137
|
-
Kovid.comma_delimit(data['deaths']),
|
|
138
|
-
Kovid.comma_delimit(data['recovered']),
|
|
139
154
|
Kovid.add_plus_sign(data['todayCases']),
|
|
155
|
+
Kovid.comma_delimit(data['deaths']),
|
|
140
156
|
Kovid.add_plus_sign(data['todayDeaths']),
|
|
157
|
+
Kovid.comma_delimit(data['active']),
|
|
158
|
+
Kovid.comma_delimit(data['recovered']),
|
|
159
|
+
Kovid.comma_delimit(data['tests']),
|
|
160
|
+
|
|
141
161
|
Kovid.comma_delimit(data['critical']),
|
|
142
162
|
Kovid.comma_delimit(data['casesPerOneMillion'])
|
|
143
163
|
]
|
|
144
164
|
end
|
|
145
165
|
|
|
166
|
+
def state_row(data)
|
|
167
|
+
[
|
|
168
|
+
Kovid.comma_delimit(data['cases']),
|
|
169
|
+
Kovid.add_plus_sign(data['todayCases']),
|
|
170
|
+
Kovid.comma_delimit(data['deaths']),
|
|
171
|
+
Kovid.add_plus_sign(data['todayDeaths']),
|
|
172
|
+
Kovid.comma_delimit(data['active']),
|
|
173
|
+
Kovid.comma_delimit(data['tests'])
|
|
174
|
+
]
|
|
175
|
+
end
|
|
176
|
+
|
|
146
177
|
def province_row(data)
|
|
147
178
|
[
|
|
148
179
|
data['stats']['confirmed'],
|
|
@@ -222,6 +253,33 @@ module Kovid
|
|
|
222
253
|
end
|
|
223
254
|
table
|
|
224
255
|
end
|
|
256
|
+
|
|
257
|
+
def top_row(data, options)
|
|
258
|
+
if options[:location] == :countries
|
|
259
|
+
return [
|
|
260
|
+
country_title(data),
|
|
261
|
+
full_country_row(data)
|
|
262
|
+
].flatten
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
[
|
|
266
|
+
data['state'].upcase,
|
|
267
|
+
country_row(data)
|
|
268
|
+
].flatten
|
|
269
|
+
end
|
|
270
|
+
|
|
271
|
+
def top_heading(options)
|
|
272
|
+
full_country_table = ['Country'.paint_white] + FULL_COUNTRY_TABLE_HEADINGS
|
|
273
|
+
full_state_table = ['State'.paint_white] + FULL_STATE_TABLE_HEADINGS
|
|
274
|
+
|
|
275
|
+
options[:location] == :countries ? full_country_table : full_state_table
|
|
276
|
+
end
|
|
277
|
+
|
|
278
|
+
def top_title(options)
|
|
279
|
+
incident = options[:incident].to_s
|
|
280
|
+
location = options[:location].to_s
|
|
281
|
+
"🌍 Top #{options[:count]} #{location} by #{incident}".upcase
|
|
282
|
+
end
|
|
225
283
|
end
|
|
226
284
|
end
|
|
227
285
|
end
|
data/lib/kovid/version.rb
CHANGED
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.6.
|
|
4
|
+
version: 0.6.14
|
|
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-
|
|
11
|
+
date: 2020-06-06 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: carmen
|