kovid 0.2.2 → 0.2.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/kovid.gemspec +3 -3
- data/lib/kovid/request.rb +18 -21
- data/lib/kovid/tablelize.rb +9 -3
- data/lib/kovid/uri_builder.rb +19 -0
- data/lib/kovid/version.rb +1 -1
- metadata +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 56417d471dca89f7d9c72b044d0dea77f426f16e4d8b2607c90d8820a341fa52
|
4
|
+
data.tar.gz: 34731329a78b414e4387e862a17dd85f90a15eb65933d1ca42a0dc6324942ddc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 344163a1a081fafa0a5e30085288981e737b98c2761864208b61e778c834771e312cfe5c36dc9456b1a53958ca28beb0d7ed1b63494f60781dab37df6e51b52c
|
7
|
+
data.tar.gz: fbacf84702f863a6c5256765a9a4d6dafaf851a0b2f735cf52f5818f070662bd7720f855a561fb2d962a53af4fd52a7415b662b788be05bacc49999d4455c14d
|
data/Gemfile.lock
CHANGED
data/kovid.gemspec
CHANGED
@@ -16,9 +16,9 @@ Gem::Specification.new do |spec|
|
|
16
16
|
|
17
17
|
spec.post_install_message = %q{
|
18
18
|
============================================================================
|
19
|
-
COVID-19 has devasted the world
|
20
|
-
with the novel coronavirus, I think stats on the issue should be
|
21
|
-
|
19
|
+
COVID-19 has devasted the world. But while we're fighting
|
20
|
+
with the novel coronavirus, I think stats on the issue should be
|
21
|
+
accessible.
|
22
22
|
|
23
23
|
There isn't much we can do now aside:
|
24
24
|
|
data/lib/kovid/request.rb
CHANGED
@@ -3,10 +3,11 @@
|
|
3
3
|
require 'json'
|
4
4
|
require_relative 'tablelize'
|
5
5
|
require_relative 'cache'
|
6
|
+
require_relative 'uri_builder'
|
6
7
|
|
7
8
|
module Kovid
|
8
9
|
class Request
|
9
|
-
|
10
|
+
COUNTRIES_PATH = UriBuilder.new('/countries').url
|
10
11
|
|
11
12
|
class << self
|
12
13
|
def by_country(country_name)
|
@@ -42,56 +43,52 @@ module Kovid
|
|
42
43
|
end
|
43
44
|
|
44
45
|
def cases
|
45
|
-
|
46
|
-
fetch_url = BASE_URL + path
|
47
|
-
|
48
|
-
response ||= JSON.parse(Typhoeus.get(fetch_url.to_s, cache_ttl: 900).response_body)
|
46
|
+
response ||= JSON.parse(Typhoeus.get(UriBuilder.new('/all').url, cache_ttl: 900).response_body)
|
49
47
|
|
50
48
|
Kovid::Tablelize.cases(response)
|
51
49
|
end
|
52
50
|
|
53
51
|
def history(country)
|
54
|
-
|
55
|
-
|
52
|
+
history_path = UriBuilder.new('/historical').url
|
53
|
+
response ||= JSON.parse(Typhoeus.get(history_path + "/#{country}", cache_ttl: 900).response_body)
|
56
54
|
|
57
|
-
response ||= JSON.parse(Typhoeus.get(fetch_url.to_s, cache_ttl: 900).response_body)
|
58
55
|
Kovid::Tablelize.history(response)
|
59
56
|
end
|
60
57
|
|
61
58
|
private
|
62
59
|
|
63
60
|
def no_case_in(country)
|
64
|
-
rows = [[
|
65
|
-
Terminal::Table.new headings: ["You checked: #{country.capitalize
|
61
|
+
rows = [['No reported cases OR check your spelling!']]
|
62
|
+
Terminal::Table.new headings: ["You checked: #{country.capitalize}"], rows: rows
|
66
63
|
end
|
67
64
|
|
68
65
|
def fetch_countries(list)
|
69
66
|
array = []
|
70
67
|
|
71
68
|
list.each do |country|
|
72
|
-
|
73
|
-
fetch_url = BASE_URL + path
|
74
|
-
|
75
|
-
array << JSON.parse(Typhoeus.get(fetch_url.to_s, cache_ttl: 900).response_body)
|
69
|
+
array << JSON.parse(Typhoeus.get(COUNTRIES_PATH + "/#{country}", cache_ttl: 900).response_body)
|
76
70
|
end
|
77
71
|
|
78
72
|
array = array.sort_by { |json| -json['cases'] }
|
79
73
|
end
|
80
74
|
|
81
75
|
def fetch_country(country_name)
|
82
|
-
|
83
|
-
fetch_url = BASE_URL + path
|
76
|
+
url = COUNTRIES_PATH + "/#{country_name}"
|
84
77
|
|
85
|
-
JSON.parse(Typhoeus.get(
|
78
|
+
JSON.parse(Typhoeus.get(url, cache_ttl: 900).response_body)
|
86
79
|
end
|
87
80
|
|
88
81
|
def fetch_state(state)
|
89
|
-
|
90
|
-
|
82
|
+
url = UriBuilder.new('/states').url
|
83
|
+
states_array = JSON.parse(Typhoeus.get(url, cache_ttl: 900).response_body)
|
91
84
|
|
92
|
-
states_array
|
85
|
+
states_array.select { |state_name| state_name['state'] == capitalize_words(state) }.first
|
86
|
+
end
|
87
|
+
|
88
|
+
private
|
93
89
|
|
94
|
-
|
90
|
+
def capitalize_words(string)
|
91
|
+
string.split.map(&:capitalize).join(' ')
|
95
92
|
end
|
96
93
|
end
|
97
94
|
end
|
data/lib/kovid/tablelize.rb
CHANGED
@@ -20,6 +20,8 @@ module Kovid
|
|
20
20
|
'Recovered'.paint_green
|
21
21
|
].freeze
|
22
22
|
|
23
|
+
FOOTER_LINE = ['------------', '------------', '------------', '------------'].freeze
|
24
|
+
|
23
25
|
def country_table(data)
|
24
26
|
headings = CASES_DEATHS_RECOVERED
|
25
27
|
rows = [[data['cases'], data['deaths'], data['recovered']]]
|
@@ -65,6 +67,8 @@ module Kovid
|
|
65
67
|
|
66
68
|
rows = []
|
67
69
|
rows << [state['cases'], state['todayCases'], state['deaths'], state['todayDeaths'], state['recovered'], state['active']]
|
70
|
+
puts
|
71
|
+
puts "‼️ Swap value of 'Recovered' for 'Active'. API scraper broke."
|
68
72
|
Terminal::Table.new(title: state['state'], headings: headings, rows: rows)
|
69
73
|
end
|
70
74
|
|
@@ -137,13 +141,15 @@ module Kovid
|
|
137
141
|
rows << row
|
138
142
|
end
|
139
143
|
|
140
|
-
rows <<
|
144
|
+
rows << FOOTER_LINE
|
141
145
|
rows << DATE_CASES_DEATHS_RECOVERED
|
142
146
|
|
143
|
-
Terminal::Table.new(title: country['standardizedCountryName'].capitalize.
|
147
|
+
Terminal::Table.new(title: country['standardizedCountryName'].split.map(&:capitalize).join(' '), headings: headings, rows: rows)
|
144
148
|
end
|
145
149
|
|
146
|
-
private
|
150
|
+
private
|
151
|
+
|
152
|
+
def comma_delimit(number)
|
147
153
|
number.to_s.chars.to_a.reverse.each_slice(3).map(&:join).join(',').reverse
|
148
154
|
end
|
149
155
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
module Kovid
|
6
|
+
class UriBuilder
|
7
|
+
attr_reader :path
|
8
|
+
|
9
|
+
BASE_URI = 'corona.lmao.ninja'
|
10
|
+
|
11
|
+
def initialize(path = '')
|
12
|
+
@path = path
|
13
|
+
end
|
14
|
+
|
15
|
+
def url
|
16
|
+
URI::HTTPS.build(host: BASE_URI, path: path).to_s
|
17
|
+
end
|
18
|
+
end
|
19
|
+
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.2.
|
4
|
+
version: 0.2.3
|
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-03-
|
11
|
+
date: 2020-03-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -151,6 +151,7 @@ files:
|
|
151
151
|
- lib/kovid/painter.rb
|
152
152
|
- lib/kovid/request.rb
|
153
153
|
- lib/kovid/tablelize.rb
|
154
|
+
- lib/kovid/uri_builder.rb
|
154
155
|
- lib/kovid/version.rb
|
155
156
|
homepage: https://github.com/siaw23/kovid
|
156
157
|
licenses:
|
@@ -161,13 +162,12 @@ metadata:
|
|
161
162
|
source_code_uri: https://github.com/siaw23/kovid
|
162
163
|
changelog_uri: https://github.com/siaw23/kovid
|
163
164
|
post_install_message: "\n ============================================================================\n
|
164
|
-
\ COVID-19 has devasted the world
|
165
|
-
novel coronavirus, I think stats on the issue should be
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
\ ============================================================================\n
|
165
|
+
\ COVID-19 has devasted the world. But while we're fighting\n with the
|
166
|
+
novel coronavirus, I think stats on the issue should be\n accessible.\n\n There
|
167
|
+
isn't much we can do now aside:\n\n * Washing our hands with soap frequently.\n
|
168
|
+
\ * Limiting our movements, how much we touch our faces & social distancing.\n
|
169
|
+
\ * Disinfecting our phones, keys, doorknobs, keyboards, etc.\n * Being
|
170
|
+
there for each other.\n\n Stay safe!\n Emmanuel Hayford.\n ============================================================================\n
|
171
171
|
\ "
|
172
172
|
rdoc_options: []
|
173
173
|
require_paths:
|