kovid 0.2.0 → 0.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c2be9d46c1a3d77e5db95af5d99c0069c06e20ad793467f49e44b581b0f20ea2
4
- data.tar.gz: bb676082e460f2384cc4ffb4a38dc0d3a08a570f9af56e8ae808804a00f6ea3a
3
+ metadata.gz: 2fc383fce99f91758770cb5df355b7bd0880f7df93e4afe522499340b2bc2130
4
+ data.tar.gz: e3728a3a48b0c7b7986b70e2dd4aca2bfd245422bf65bc5b0b6ffea7e8f32f81
5
5
  SHA512:
6
- metadata.gz: edca0fbc53d67571c21b98a27c3d4cdc4e1c5837c659dfc4220a9753a37bb32230a378e16c0a771c581a3b50c508d398ab18d02b946610d120383c024e994eb7
7
- data.tar.gz: 1dd993547fc53ebcc629caf5f16ce22a6d54b6261558a23a9b9e047df05a635376b058f85ead8f81113d280f2ca711362828a86384316156cdad8c72e40bd8db
6
+ metadata.gz: 8604d3d7720a5b904a4cfc025d961ebdef4b7cfc863cb444f3fce2b9e603f4cab2b80f81e768184c7e330973ecd5696b889b783ff4e48af4e8ce2862b499fb39
7
+ data.tar.gz: 5c408b62c29e811cfda4e1dad700077317dc67812d58d9ca03264bfbdfed39c6793dd079dfb654340643e6c7b4c334ba609281886a067174992fe9f928f7a69b
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kovid (0.1.14)
4
+ kovid (0.2.0)
5
5
  colorize
6
6
  terminal-table
7
7
  thor
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # 🦠 Kovid
2
2
 
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 and since I work mostly in the terminal, like most of you, I thought I'd build this to put the data right at our fingertips.
4
-
3
+ [gem]: https://rubygems.org/gems/kovid
5
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.
6
6
 
7
7
  Please feel free to contribute or suggest ideas!
8
8
 
@@ -15,13 +15,6 @@ Before installing:
15
15
  ✌️ Run `gem install kovid`
16
16
 
17
17
 
18
- After installing:
19
-
20
- ☝️ Avoid touching your eyes, nose and mouth with unwashed hands later.
21
-
22
- ✌️ Disinfect your phones, keys, doorknobs and anything you touch more often than you should.
23
-
24
-
25
18
 
26
19
  ## ⚒️ Usage
27
20
 
@@ -43,6 +36,9 @@ You can run `kovid --help` to see the full list of available commands.
43
36
 
44
37
  You can compare as many countries as you want.
45
38
 
39
+ 😷 **History**
40
+ * `kovid history italy`
41
+
46
42
  😷 **Total figures**
47
43
  * `kovid cases`
48
44
 
@@ -59,7 +55,7 @@ If the location contains spaces: `kovid check "Diamond Princess"`
59
55
 
60
56
  For full table info on a country:
61
57
 
62
- `kovid check italy -f` OR `kovid check italy -f --full`
58
+ `kovid check italy -f` OR `kovid check italy --full`
63
59
 
64
60
  ![kovid](https://i.gyazo.com/789fa6795d06f529a9b5f37cb51fb516.png "Covid data.")
65
61
 
@@ -81,6 +77,12 @@ To fetch state-specific data run:
81
77
 
82
78
  ![kovid](https://i.gyazo.com/d00b1c5bbb6251cbd517f801c856ba66.png "Covid data.")
83
79
 
80
+ You can check historical statistics by running
81
+
82
+ `kovid history COUNTRY` eg:
83
+
84
+ ![kovid](https://i.gyazo.com/45d306694cbf793f2e4f7646854cbac8.png "Covid data.")
85
+
84
86
  To check for total figures:
85
87
 
86
88
  `kovid cases`
data/kovid.gemspec CHANGED
@@ -23,7 +23,8 @@ Gem::Specification.new do |spec|
23
23
  There isn't much we can do now aside:
24
24
 
25
25
  * Washing our hands with soap frequently.
26
- * Limiting our movements and social distancing.
26
+ * Limiting our movements, how much we touch our faces & social distancing.
27
+ * Disinfecting our phones, keys, doorknobs, keyboards, etc.
27
28
  * Being there for each other.
28
29
 
29
30
  Stay safe!
data/lib/kovid/cli.rb CHANGED
@@ -42,5 +42,10 @@ module Kovid
42
42
  def cases
43
43
  puts Kovid.cases
44
44
  end
45
+
46
+ desc 'history COUNTRY', 'Return history of incidents of COUNTRY'
47
+ def history(country)
48
+ puts Kovid.history(country)
49
+ end
45
50
  end
46
51
  end
data/lib/kovid/request.rb CHANGED
@@ -50,6 +50,14 @@ module Kovid
50
50
  Kovid::Tablelize.cases(response)
51
51
  end
52
52
 
53
+ def history(country)
54
+ path = '/historical'
55
+ fetch_url = BASE_URL + path + "/#{country}"
56
+
57
+ response ||= JSON.parse(Typhoeus.get(fetch_url.to_s, cache_ttl: 900).response_body)
58
+ Kovid::Tablelize.history(response)
59
+ end
60
+
53
61
  private
54
62
 
55
63
  def no_case_in(country)
@@ -2,7 +2,8 @@
2
2
 
3
3
  require 'terminal-table'
4
4
  require_relative 'painter'
5
-
5
+ require 'pry'
6
+ require 'date'
6
7
  module Kovid
7
8
  class Tablelize
8
9
  class << self
@@ -12,6 +13,13 @@ module Kovid
12
13
  'Recovered'.paint_green
13
14
  ].freeze
14
15
 
16
+ DATE_CASES_DEATHS_RECOVERED = [
17
+ 'Date'.paint_white,
18
+ 'Cases'.paint_white,
19
+ 'Deaths'.paint_red,
20
+ 'Recovered'.paint_green
21
+ ].freeze
22
+
15
23
  def country_table(data)
16
24
  headings = CASES_DEATHS_RECOVERED
17
25
  rows = [[data['cases'], data['deaths'], data['recovered']]]
@@ -111,8 +119,37 @@ module Kovid
111
119
  headings = CASES_DEATHS_RECOVERED
112
120
  rows = [[cases['cases'], cases['deaths'], cases['recovered']]]
113
121
 
114
- Terminal::Table.new(title: 'Total # of incidents', headings: headings, rows: rows)
122
+ Terminal::Table.new(title: 'Total Number of Incidents Worldwide', headings: headings, rows: rows)
115
123
  end
124
+
125
+ def history(country)
126
+ headings = DATE_CASES_DEATHS_RECOVERED
127
+ rows = []
128
+ stats = country['timeline'].values.map(&:values).transpose.each do |data|
129
+ data.map! { |number| comma_delimit(number) }
130
+ end
131
+
132
+ dates = country['timeline']['cases'].keys
133
+
134
+ data = stats.each_with_index do |val, index|
135
+ val.unshift(Date.parse(Date.strptime(dates[index], '%m/%d/%y').to_s).strftime('%d %b, %y'))
136
+ end.each do |row|
137
+ rows << row
138
+ end
139
+
140
+
141
+ rows << ["------------", "------------","------------","------------"]
142
+ rows << DATE_CASES_DEATHS_RECOVERED
143
+
144
+ Terminal::Table.new(title: country['standardizedCountryName'].capitalize.to_s, headings: headings, rows: rows)
145
+ end
146
+
147
+ private def comma_delimit(number)
148
+ number.to_s.chars.to_a.reverse.each_slice(3).map(&:join).join(',').reverse
149
+ end
150
+
116
151
  end
152
+
153
+
117
154
  end
118
155
  end
data/lib/kovid/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kovid
4
- VERSION = '0.2.0'
4
+ VERSION = '0.2.1'
5
5
  end
data/lib/kovid.rb CHANGED
@@ -35,4 +35,8 @@ module Kovid
35
35
  def cases
36
36
  Kovid::Request.cases
37
37
  end
38
+
39
+ def history(country)
40
+ Kovid::Request.history(country)
41
+ end
38
42
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kovid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emmanuel Hayford
@@ -164,8 +164,10 @@ post_install_message: "\n ===================================================
164
164
  \ COVID-19 has devasted the world! But while we're fighting\n with the
165
165
  novel coronavirus, I think stats on the issue should be easily\n reachable.\n\n
166
166
  \ There isn't much we can do now aside:\n\n * Washing our hands with soap
167
- frequently.\n * Limiting our movements and social distancing.\n * Being
168
- there for each other.\n\n Stay safe!\n Emmanuel Hayford.\n ============================================================================\n
167
+ frequently.\n * Limiting our movements, how much we touch our faces & social
168
+ distancing.\n * Disinfecting our phones, keys, doorknobs, keyboards, etc.\n
169
+ \ * Being there for each other.\n\n Stay safe!\n Emmanuel Hayford.\n
170
+ \ ============================================================================\n
169
171
  \ "
170
172
  rdoc_options: []
171
173
  require_paths: