kovid 0.6.13 โ 0.7.0
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 +13 -30
- data/README.md +0 -10
- data/kovid.gemspec +0 -20
- data/lib/kovid/constants.rb +72 -5
- data/lib/kovid/helpers.rb +1 -9
- data/lib/kovid/historians.rb +33 -28
- data/lib/kovid/request.rb +24 -24
- data/lib/kovid/tablelize.rb +21 -9
- data/lib/kovid/version.rb +1 -1
- metadata +6 -27
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: acb8468524e33ff58574c2910dd1af5682b2e6bdd8d0fe61c4d497156fe4ff17
|
|
4
|
+
data.tar.gz: 58f2430edf6b6cc104c815761205fa2b0532e7fe133af7fe114b6d7608651b69
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d91ac4ad0e990714c8fdd5ac8ced650abdb6c22525c8a61a9b8b089d027c7991cf4629dc03aff77f934d412db561065ed8cdc2dff4b7b86b9b07b38e523e7c11
|
|
7
|
+
data.tar.gz: b60f261d152aa46784ee6eacafacd59aeae8906637ccf76721e166e49632680c23aed6d61642487037295f49ea02adb4c8189aa08bf7b919b277caec35016d55
|
data/Gemfile.lock
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
kovid (0.
|
|
5
|
-
carmen (~> 1.1.3)
|
|
4
|
+
kovid (0.7.0)
|
|
6
5
|
rainbow (~> 3.0)
|
|
7
6
|
terminal-table (~> 1.8)
|
|
8
7
|
thor (~> 1.0)
|
|
@@ -11,52 +10,36 @@ PATH
|
|
|
11
10
|
GEM
|
|
12
11
|
remote: https://rubygems.org/
|
|
13
12
|
specs:
|
|
14
|
-
activesupport (6.0.2.2)
|
|
15
|
-
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
16
|
-
i18n (>= 0.7, < 2)
|
|
17
|
-
minitest (~> 5.1)
|
|
18
|
-
tzinfo (~> 1.1)
|
|
19
|
-
zeitwerk (~> 2.2)
|
|
20
|
-
carmen (1.1.3)
|
|
21
|
-
activesupport (>= 3.0.0)
|
|
22
|
-
concurrent-ruby (1.1.6)
|
|
23
13
|
diff-lcs (1.3)
|
|
24
14
|
docile (1.3.2)
|
|
25
|
-
ethon (0.
|
|
26
|
-
ffi (>= 1.
|
|
27
|
-
ffi (1.
|
|
28
|
-
|
|
29
|
-
concurrent-ruby (~> 1.0)
|
|
30
|
-
minitest (5.14.0)
|
|
31
|
-
rainbow (3.0.0)
|
|
15
|
+
ethon (0.15.0)
|
|
16
|
+
ffi (>= 1.15.0)
|
|
17
|
+
ffi (1.15.5)
|
|
18
|
+
rainbow (3.1.1)
|
|
32
19
|
rake (12.3.3)
|
|
33
20
|
rspec (3.9.0)
|
|
34
21
|
rspec-core (~> 3.9.0)
|
|
35
22
|
rspec-expectations (~> 3.9.0)
|
|
36
23
|
rspec-mocks (~> 3.9.0)
|
|
37
|
-
rspec-core (3.9.
|
|
38
|
-
rspec-support (~> 3.9.
|
|
39
|
-
rspec-expectations (3.9.
|
|
24
|
+
rspec-core (3.9.2)
|
|
25
|
+
rspec-support (~> 3.9.3)
|
|
26
|
+
rspec-expectations (3.9.2)
|
|
40
27
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
41
28
|
rspec-support (~> 3.9.0)
|
|
42
29
|
rspec-mocks (3.9.1)
|
|
43
30
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
44
31
|
rspec-support (~> 3.9.0)
|
|
45
|
-
rspec-support (3.9.
|
|
32
|
+
rspec-support (3.9.3)
|
|
46
33
|
simplecov (0.18.5)
|
|
47
34
|
docile (~> 1.1)
|
|
48
35
|
simplecov-html (~> 0.11)
|
|
49
36
|
simplecov-html (0.12.2)
|
|
50
37
|
terminal-table (1.8.0)
|
|
51
38
|
unicode-display_width (~> 1.1, >= 1.1.1)
|
|
52
|
-
thor (1.
|
|
53
|
-
|
|
54
|
-
typhoeus (1.3.1)
|
|
39
|
+
thor (1.2.1)
|
|
40
|
+
typhoeus (1.4.0)
|
|
55
41
|
ethon (>= 0.9.0)
|
|
56
|
-
|
|
57
|
-
thread_safe (~> 0.1)
|
|
58
|
-
unicode-display_width (1.7.0)
|
|
59
|
-
zeitwerk (2.3.0)
|
|
42
|
+
unicode-display_width (1.8.0)
|
|
60
43
|
|
|
61
44
|
PLATFORMS
|
|
62
45
|
ruby
|
|
@@ -68,4 +51,4 @@ DEPENDENCIES
|
|
|
68
51
|
simplecov (~> 0.18)
|
|
69
52
|
|
|
70
53
|
BUNDLED WITH
|
|
71
|
-
2.
|
|
54
|
+
2.3.9
|
data/README.md
CHANGED
|
@@ -85,10 +85,6 @@ ___
|
|
|
85
85
|
|
|
86
86
|
**NOTE:** If you find it irritating to have to type `kovid state STATE`, `covid state STATE` works as well.
|
|
87
87
|
|
|
88
|
-
#### Histogram (Experimental) ๐งช
|
|
89
|
-
|
|
90
|
-
`kovid histogram COUNTRY M.YY` (draws a histogram of cases in the given month `M` and years `YY`)
|
|
91
|
-
(If the histogram appears messy, you might want to resize your window.)
|
|
92
88
|
|
|
93
89
|
#### Commands Details
|
|
94
90
|
To fetch basic data on a country run:
|
|
@@ -171,12 +167,6 @@ To fetch more number of countries or US states you can pass N. eg:
|
|
|
171
167
|
|
|
172
168
|

|
|
173
169
|
|
|
174
|
-
## ๐ฉ๐พโ๐ฌ Experimental Feature
|
|
175
|
-
|
|
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.
|
|
177
|
-
|
|
178
|
-

|
|
179
|
-
|
|
180
170
|
|
|
181
171
|
## Data Source
|
|
182
172
|
> [JHU CSSE GISand Data](https://gisanddata.maps.arcgis.com/apps/opsdashboard/index.html#/bda7594740fd40299423467b48e9ecf6) and https://www.worldometers.info/coronavirus/ via [NovelCOVID/API](https://github.com/novelcovid/api)
|
data/kovid.gemspec
CHANGED
|
@@ -22,7 +22,6 @@ Gem::Specification.new do |spec|
|
|
|
22
22
|
spec.metadata['source_code_uri'] = 'https://github.com/siaw23/kovid'
|
|
23
23
|
spec.metadata['changelog_uri'] = 'https://github.com/siaw23/kovid'
|
|
24
24
|
|
|
25
|
-
spec.add_dependency 'carmen', '~> 1.1.3'
|
|
26
25
|
spec.add_dependency 'rainbow', '~> 3.0'
|
|
27
26
|
spec.add_dependency 'terminal-table', '~> 1.8'
|
|
28
27
|
spec.add_dependency 'thor', '~> 1.0'
|
|
@@ -40,23 +39,4 @@ Gem::Specification.new do |spec|
|
|
|
40
39
|
spec.bindir = 'exe'
|
|
41
40
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
42
41
|
spec.require_paths = ['lib']
|
|
43
|
-
|
|
44
|
-
spec.post_install_message = "
|
|
45
|
-
============================================================================
|
|
46
|
-
COVID-19 has devasted the world. While we're fighting
|
|
47
|
-
with the novel coronavirus, I think stats on the issue should be
|
|
48
|
-
accessible.
|
|
49
|
-
|
|
50
|
-
There isn't much we can do now besides following procedures and hoping
|
|
51
|
-
for the best.
|
|
52
|
-
|
|
53
|
-
Stay safe!
|
|
54
|
-
Emmanuel Hayford.
|
|
55
|
-
https://emmanuelhayford.com
|
|
56
|
-
|
|
57
|
-
PS: I'm in search of a Rails/Ruby job.
|
|
58
|
-
|
|
59
|
-
You can hire me (siawmensah@gmail.com).
|
|
60
|
-
============================================================================
|
|
61
|
-
"
|
|
62
42
|
end
|
data/lib/kovid/constants.rb
CHANGED
|
@@ -13,8 +13,9 @@ module Kovid
|
|
|
13
13
|
'Cases Today'.paint_white,
|
|
14
14
|
'Deaths'.paint_red,
|
|
15
15
|
'Deaths Today'.paint_red,
|
|
16
|
+
'Active'.paint_yellow,
|
|
16
17
|
'Recovered'.paint_green,
|
|
17
|
-
'Tests'.paint_white
|
|
18
|
+
'Tests'.paint_white
|
|
18
19
|
].freeze
|
|
19
20
|
|
|
20
21
|
DATE_CASES_DEATHS_RECOVERED = [
|
|
@@ -43,11 +44,13 @@ module Kovid
|
|
|
43
44
|
COMPARE_COUNTRY_TABLE_FULL = [
|
|
44
45
|
'Country'.paint_white,
|
|
45
46
|
'Cases'.paint_white,
|
|
46
|
-
'Deaths'.paint_red,
|
|
47
|
-
'Recovered'.paint_green,
|
|
48
47
|
'Cases Today'.paint_white,
|
|
48
|
+
'Deaths'.paint_red,
|
|
49
49
|
'Deaths Today'.paint_red,
|
|
50
|
+
'Active'.paint_yellow,
|
|
51
|
+
'Recovered'.paint_green,
|
|
50
52
|
'Critical'.paint_yellow,
|
|
53
|
+
'Tests'.paint_white,
|
|
51
54
|
'Cases/Million'.paint_white
|
|
52
55
|
].freeze
|
|
53
56
|
|
|
@@ -57,17 +60,20 @@ module Kovid
|
|
|
57
60
|
'Cases Today'.paint_white,
|
|
58
61
|
'Deaths'.paint_red,
|
|
59
62
|
'Deaths Today'.paint_red,
|
|
63
|
+
'Active'.paint_yellow,
|
|
60
64
|
'Recovered'.paint_green,
|
|
61
65
|
'Tests'.paint_white
|
|
62
66
|
].freeze
|
|
63
67
|
|
|
64
68
|
FULL_COUNTRY_TABLE_HEADINGS = [
|
|
65
69
|
'Cases'.paint_white,
|
|
66
|
-
'Deaths'.paint_red,
|
|
67
|
-
'Recovered'.paint_green,
|
|
68
70
|
'Cases Today'.paint_white,
|
|
71
|
+
'Deaths'.paint_red,
|
|
69
72
|
'Deaths Today'.paint_red,
|
|
73
|
+
'Active'.paint_yellow,
|
|
74
|
+
'Recovered'.paint_green,
|
|
70
75
|
'Critical'.paint_yellow,
|
|
76
|
+
'Tests'.paint_white,
|
|
71
77
|
'Cases/Million'.paint_white
|
|
72
78
|
].freeze
|
|
73
79
|
|
|
@@ -110,6 +116,9 @@ module Kovid
|
|
|
110
116
|
|
|
111
117
|
FOOTER_LINE_FOUR_COLUMNS = FOOTER_LINE_COLUMN * 4
|
|
112
118
|
|
|
119
|
+
# Add footer if rows exceed this number
|
|
120
|
+
ADD_FOOTER_SIZE = 10
|
|
121
|
+
|
|
113
122
|
COUNTRY_LETTERS = 'A'.upto('Z').with_index(127_462).to_h.freeze
|
|
114
123
|
|
|
115
124
|
RIGHT_ALIGN_COLUMNS = {
|
|
@@ -118,5 +127,63 @@ module Kovid
|
|
|
118
127
|
compare_us_states: [1, 2, 3, 4, 5],
|
|
119
128
|
compare_provinces: [1, 2, 3]
|
|
120
129
|
}.freeze
|
|
130
|
+
|
|
131
|
+
USA_ABBREVIATIONS = {
|
|
132
|
+
"al" => "Alabama",
|
|
133
|
+
"ak" => "Alaska",
|
|
134
|
+
"az" => "Arizona",
|
|
135
|
+
"ar" => "Arkansas",
|
|
136
|
+
"ca" => "California",
|
|
137
|
+
"cz" => "Canal Zone",
|
|
138
|
+
"co" => "Colorado",
|
|
139
|
+
"ct" => "Connecticut",
|
|
140
|
+
"de" => "Delaware",
|
|
141
|
+
"dc" => "District of Columbia",
|
|
142
|
+
"fl" => "Florida",
|
|
143
|
+
"ga" => "Georgia",
|
|
144
|
+
"gu" => "Guam",
|
|
145
|
+
"hi" => "Hawaii",
|
|
146
|
+
"id" => "Idaho",
|
|
147
|
+
"il" => "Illinois",
|
|
148
|
+
"in" => "Indiana",
|
|
149
|
+
"ia" => "Iowa",
|
|
150
|
+
"ks" => "Kansas",
|
|
151
|
+
"ky" => "Kentucky",
|
|
152
|
+
"la" => "Louisiana",
|
|
153
|
+
"me" => "Maine",
|
|
154
|
+
"md" => "Maryland",
|
|
155
|
+
"ma" => "Massachusetts",
|
|
156
|
+
"mi" => "Michigan",
|
|
157
|
+
"mn" => "Minnesota",
|
|
158
|
+
"ms" => "Mississippi",
|
|
159
|
+
"mo" => "Missouri",
|
|
160
|
+
"mt" => "Montana",
|
|
161
|
+
"ne" => "Nebraska",
|
|
162
|
+
"nv" => "Nevada",
|
|
163
|
+
"nh" => "New Hampshire",
|
|
164
|
+
"nj" => "New Jersey",
|
|
165
|
+
"nm" => "New Mexico",
|
|
166
|
+
"ny" => "New York",
|
|
167
|
+
"nc" => "North Carolina",
|
|
168
|
+
"nd" => "North Dakota",
|
|
169
|
+
"oh" => "Ohio",
|
|
170
|
+
"ok" => "Oklahoma",
|
|
171
|
+
"or" => "Oregon",
|
|
172
|
+
"pa" => "Pennsylvania",
|
|
173
|
+
"pr" => "Puerto Rico",
|
|
174
|
+
"ri" => "Rhode Island",
|
|
175
|
+
"sc" => "South Carolina",
|
|
176
|
+
"sd" => "South Dakota",
|
|
177
|
+
"tn" => "Tennessee",
|
|
178
|
+
"tx" => "Texas",
|
|
179
|
+
"ut" => "Utah",
|
|
180
|
+
"vt" => "Vermont",
|
|
181
|
+
"vi" => "Virgin Islands",
|
|
182
|
+
"va" => "Virginia",
|
|
183
|
+
"wa" => "Washington",
|
|
184
|
+
"wv" => "West Virginia",
|
|
185
|
+
"wi" => "Wisconsin",
|
|
186
|
+
"wy" => "Wyoming"
|
|
187
|
+
}
|
|
121
188
|
end
|
|
122
189
|
end
|
data/lib/kovid/helpers.rb
CHANGED
|
@@ -25,15 +25,7 @@ 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
|
-
|
|
36
|
-
lookup = us.subregions.coded(state) || us.subregions.named(state)
|
|
37
|
-
lookup ? lookup.name : state
|
|
29
|
+
Kovid::Constants::USA_ABBREVIATIONS.fetch(state.downcase, state)
|
|
38
30
|
end
|
|
39
31
|
end
|
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']&.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']&.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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require 'json'
|
|
4
|
-
require '
|
|
4
|
+
require 'erb'
|
|
5
5
|
require_relative 'tablelize'
|
|
6
6
|
require_relative 'cache'
|
|
7
7
|
require_relative 'uri_builder'
|
|
@@ -162,13 +162,7 @@ module Kovid
|
|
|
162
162
|
end
|
|
163
163
|
|
|
164
164
|
def history(country, days)
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
response = JSON.parse(
|
|
168
|
-
Typhoeus.get(
|
|
169
|
-
history_path + "/#{country}", cache_ttl: 900
|
|
170
|
-
).response_body
|
|
171
|
-
)
|
|
165
|
+
response = fetch_history(country)
|
|
172
166
|
|
|
173
167
|
if response.key?('message')
|
|
174
168
|
not_found(country) do |c|
|
|
@@ -182,14 +176,8 @@ module Kovid
|
|
|
182
176
|
end
|
|
183
177
|
|
|
184
178
|
def history_us_state(state, days)
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
response = JSON.parse(
|
|
189
|
-
Typhoeus.get(
|
|
190
|
-
history_path + "/#{state}", cache_ttl: 900
|
|
191
|
-
).response_body
|
|
192
|
-
)
|
|
179
|
+
state = Kovid.lookup_us_state(state).downcase
|
|
180
|
+
response = fetch_us_history(state)
|
|
193
181
|
|
|
194
182
|
if response.respond_to?(:key?) && response.key?('message')
|
|
195
183
|
return not_found(state)
|
|
@@ -201,22 +189,20 @@ module Kovid
|
|
|
201
189
|
cases = usacounties_aggregator(response, 'cases')
|
|
202
190
|
deaths = usacounties_aggregator(response, 'deaths')
|
|
203
191
|
|
|
204
|
-
# normalize data so we can call Kovid::Tablelize.history on US State data
|
|
205
192
|
response = {
|
|
206
193
|
'state' => state,
|
|
207
194
|
'timeline' => { 'cases' => cases, 'deaths' => deaths }
|
|
208
195
|
}
|
|
209
196
|
|
|
210
|
-
Kovid::Tablelize.
|
|
197
|
+
Kovid::Tablelize.history_us_state(response, days)
|
|
211
198
|
rescue JSON::ParserError
|
|
212
199
|
puts SERVER_DOWN
|
|
213
200
|
end
|
|
214
201
|
|
|
215
202
|
def histogram(country, date)
|
|
216
|
-
history_path = UriBuilder.new('/v2/historical').url
|
|
217
203
|
response = JSON.parse(
|
|
218
204
|
Typhoeus.get(
|
|
219
|
-
|
|
205
|
+
HISTORICAL_URL + "/#{country}", cache_ttl: 900
|
|
220
206
|
).response_body
|
|
221
207
|
)
|
|
222
208
|
|
|
@@ -280,7 +266,7 @@ module Kovid
|
|
|
280
266
|
def fetch_country(country_name)
|
|
281
267
|
# TODO: Match ISOs to full country names
|
|
282
268
|
country_name = 'nl' if country_name == 'netherlands'
|
|
283
|
-
country_url = COUNTRIES_PATH + "/#{country_name}"
|
|
269
|
+
country_url = COUNTRIES_PATH + "/#{ERB::Util.url_encode(country_name)}"
|
|
284
270
|
|
|
285
271
|
JSON.parse(Typhoeus.get(country_url, cache_ttl: 900).response_body)
|
|
286
272
|
end
|
|
@@ -312,6 +298,22 @@ module Kovid
|
|
|
312
298
|
end.first
|
|
313
299
|
end
|
|
314
300
|
|
|
301
|
+
def fetch_history(country)
|
|
302
|
+
JSON.parse(
|
|
303
|
+
Typhoeus.get(
|
|
304
|
+
HISTORICAL_URL + "/#{ERB::Util.url_encode(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 + "/#{ERB::Util.url_encode(state)}", cache_ttl: 900
|
|
313
|
+
).response_body
|
|
314
|
+
)
|
|
315
|
+
end
|
|
316
|
+
|
|
315
317
|
def aggregator(isos, meth)
|
|
316
318
|
countries_array = JSON.parse(countries_request)
|
|
317
319
|
country_array = countries_array.select do |hash|
|
|
@@ -325,9 +327,7 @@ module Kovid
|
|
|
325
327
|
end
|
|
326
328
|
|
|
327
329
|
def countries_request
|
|
328
|
-
Typhoeus.get(
|
|
329
|
-
UriBuilder.new('/v2/countries').url, cache_ttl: 900
|
|
330
|
-
).response_body
|
|
330
|
+
Typhoeus.get(COUNTRIES_PATH, cache_ttl: 900).response_body
|
|
331
331
|
end
|
|
332
332
|
|
|
333
333
|
def countries_aggregator(country_array)
|
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
|
|
|
@@ -136,7 +136,6 @@ module Kovid
|
|
|
136
136
|
]
|
|
137
137
|
end
|
|
138
138
|
|
|
139
|
-
# Also works for state
|
|
140
139
|
def country_row(data)
|
|
141
140
|
[
|
|
142
141
|
Kovid.comma_delimit(data['cases']),
|
|
@@ -144,6 +143,7 @@ module Kovid
|
|
|
144
143
|
Kovid.comma_delimit(data['deaths']),
|
|
145
144
|
Kovid.add_plus_sign(data['todayDeaths']),
|
|
146
145
|
Kovid.comma_delimit(data['active']),
|
|
146
|
+
Kovid.comma_delimit(data['recovered']),
|
|
147
147
|
Kovid.comma_delimit(data['tests'])
|
|
148
148
|
]
|
|
149
149
|
end
|
|
@@ -151,15 +151,28 @@ module Kovid
|
|
|
151
151
|
def full_country_row(data)
|
|
152
152
|
[
|
|
153
153
|
Kovid.comma_delimit(data['cases']),
|
|
154
|
-
Kovid.comma_delimit(data['deaths']),
|
|
155
|
-
Kovid.comma_delimit(data['recovered']),
|
|
156
154
|
Kovid.add_plus_sign(data['todayCases']),
|
|
155
|
+
Kovid.comma_delimit(data['deaths']),
|
|
157
156
|
Kovid.add_plus_sign(data['todayDeaths']),
|
|
157
|
+
Kovid.comma_delimit(data['active']),
|
|
158
|
+
Kovid.comma_delimit(data['recovered']),
|
|
158
159
|
Kovid.comma_delimit(data['critical']),
|
|
160
|
+
Kovid.comma_delimit(data['tests']),
|
|
159
161
|
Kovid.comma_delimit(data['casesPerOneMillion'])
|
|
160
162
|
]
|
|
161
163
|
end
|
|
162
164
|
|
|
165
|
+
def state_row(data)
|
|
166
|
+
[
|
|
167
|
+
Kovid.comma_delimit(data['cases']),
|
|
168
|
+
Kovid.add_plus_sign(data['todayCases']),
|
|
169
|
+
Kovid.comma_delimit(data['deaths']),
|
|
170
|
+
Kovid.add_plus_sign(data['todayDeaths']),
|
|
171
|
+
Kovid.comma_delimit(data['active']),
|
|
172
|
+
Kovid.comma_delimit(data['tests'])
|
|
173
|
+
]
|
|
174
|
+
end
|
|
175
|
+
|
|
163
176
|
def province_row(data)
|
|
164
177
|
[
|
|
165
178
|
data['stats']['confirmed'],
|
|
@@ -255,17 +268,16 @@ module Kovid
|
|
|
255
268
|
end
|
|
256
269
|
|
|
257
270
|
def top_heading(options)
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
end
|
|
271
|
+
full_country_table = ['Country'.paint_white] + FULL_COUNTRY_TABLE_HEADINGS
|
|
272
|
+
full_state_table = ['State'.paint_white] + FULL_STATE_TABLE_HEADINGS
|
|
261
273
|
|
|
262
|
-
[
|
|
274
|
+
options[:location] == :countries ? full_country_table : full_state_table
|
|
263
275
|
end
|
|
264
276
|
|
|
265
277
|
def top_title(options)
|
|
266
278
|
incident = options[:incident].to_s
|
|
267
279
|
location = options[:location].to_s
|
|
268
|
-
"๐ Top #{options[:count]} #{location}
|
|
280
|
+
"๐ Top #{options[:count]} #{location} by #{incident}".upcase
|
|
269
281
|
end
|
|
270
282
|
end
|
|
271
283
|
end
|
data/lib/kovid/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,29 +1,15 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: kovid
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.7.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Emmanuel Hayford
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2022-03-21 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
|
-
- !ruby/object:Gem::Dependency
|
|
14
|
-
name: carmen
|
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
|
16
|
-
requirements:
|
|
17
|
-
- - "~>"
|
|
18
|
-
- !ruby/object:Gem::Version
|
|
19
|
-
version: 1.1.3
|
|
20
|
-
type: :runtime
|
|
21
|
-
prerelease: false
|
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
-
requirements:
|
|
24
|
-
- - "~>"
|
|
25
|
-
- !ruby/object:Gem::Version
|
|
26
|
-
version: 1.1.3
|
|
27
13
|
- !ruby/object:Gem::Dependency
|
|
28
14
|
name: rainbow
|
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -140,14 +126,7 @@ metadata:
|
|
|
140
126
|
homepage_uri: https://github.com/siaw23/kovid
|
|
141
127
|
source_code_uri: https://github.com/siaw23/kovid
|
|
142
128
|
changelog_uri: https://github.com/siaw23/kovid
|
|
143
|
-
post_install_message:
|
|
144
|
-
\ COVID-19 has devasted the world. While we're fighting\n with the novel
|
|
145
|
-
coronavirus, I think stats on the issue should be\n accessible.\n\n There
|
|
146
|
-
isn't much we can do now besides following procedures and hoping\n for the
|
|
147
|
-
best.\n\n Stay safe!\n Emmanuel Hayford.\n https://emmanuelhayford.com\n\n
|
|
148
|
-
\ PS: I'm in search of a Rails/Ruby job.\n\n You can hire me (siawmensah@gmail.com).\n
|
|
149
|
-
\ ============================================================================\n
|
|
150
|
-
\ "
|
|
129
|
+
post_install_message:
|
|
151
130
|
rdoc_options: []
|
|
152
131
|
require_paths:
|
|
153
132
|
- lib
|
|
@@ -162,8 +141,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
162
141
|
- !ruby/object:Gem::Version
|
|
163
142
|
version: '0'
|
|
164
143
|
requirements: []
|
|
165
|
-
rubygems_version: 3.
|
|
166
|
-
signing_key:
|
|
144
|
+
rubygems_version: 3.0.9
|
|
145
|
+
signing_key:
|
|
167
146
|
specification_version: 4
|
|
168
147
|
summary: A CLI to fetch and compare the 2019 coronavirus pandemic statistics.
|
|
169
148
|
test_files: []
|