covid19 0.1.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 +7 -0
- data/.gitattributes +2 -0
- data/.gitignore +22 -0
- data/.rspec +3 -0
- data/.rubocop.yml +62 -0
- data/.travis.yml +64 -0
- data/CHANGELOG.md +13 -0
- data/CODEOWNERS +7 -0
- data/Gemfile +7 -0
- data/LICENSE.md +24 -0
- data/README.md +88 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/covid19.gemspec +30 -0
- data/exe/covid19 +164 -0
- data/lib/covid19.rb +43 -0
- data/lib/covid19/version.rb +3 -0
- data/spec/covid19_spec.rb +5 -0
- data/spec/spec_helper.rb +14 -0
- data/stale.yml +17 -0
- data/testing/covid19 +165 -0
- metadata +135 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: f35dbf85b81c455721c10fc03a22be3cc2b2e7ca7e3e0ec3d4e523780f5148cb
|
|
4
|
+
data.tar.gz: b1df7e8671ecdbb7d7a66a857648a2586c215001e927bd3ee9b3f5e90b8240a7
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 9e8f7b394546576506318b922988e682ecc1a7c447bf9e6218d4b19cc0c57c044f0ca14fc7dab554c5567e2503f243af5cd63c47fe2a365eddb2aba6d1477565
|
|
7
|
+
data.tar.gz: 9921a44a2a1e85cca225447203fc2fed6349515a77758ba94791843b44bbad349814fbeb322a4e9a6d45e617d84cb0d32be054ec8c2223e11aa8d41a6340096c
|
data/.gitattributes
ADDED
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
AllCops:
|
|
2
|
+
TargetRubyVersion: 2.5
|
|
3
|
+
|
|
4
|
+
Layout/IndentationWidth:
|
|
5
|
+
Width: 4
|
|
6
|
+
|
|
7
|
+
Layout/LineLength:
|
|
8
|
+
Enabled: false
|
|
9
|
+
|
|
10
|
+
Layout/SpaceAroundOperators:
|
|
11
|
+
Enabled: false
|
|
12
|
+
|
|
13
|
+
Metrics/AbcSize:
|
|
14
|
+
Enabled: false
|
|
15
|
+
|
|
16
|
+
Metrics/BlockLength:
|
|
17
|
+
Enabled: false
|
|
18
|
+
|
|
19
|
+
Metrics/ClassLength:
|
|
20
|
+
Enabled: false
|
|
21
|
+
|
|
22
|
+
Metrics/CyclomaticComplexity:
|
|
23
|
+
Enabled: false
|
|
24
|
+
|
|
25
|
+
Metrics/MethodLength:
|
|
26
|
+
Enabled: false
|
|
27
|
+
|
|
28
|
+
Metrics/PerceivedComplexity:
|
|
29
|
+
Enabled: false
|
|
30
|
+
|
|
31
|
+
Style/FrozenStringLiteralComment:
|
|
32
|
+
Enabled: false
|
|
33
|
+
|
|
34
|
+
Style/HashEachMethods:
|
|
35
|
+
Enabled: false
|
|
36
|
+
|
|
37
|
+
Style/HashSyntax:
|
|
38
|
+
Enabled: false
|
|
39
|
+
|
|
40
|
+
Style/HashTransformKeys:
|
|
41
|
+
Enabled: false
|
|
42
|
+
|
|
43
|
+
Style/HashTransformValues:
|
|
44
|
+
Enabled: false
|
|
45
|
+
|
|
46
|
+
Style/RaiseArgs:
|
|
47
|
+
EnforcedStyle: compact
|
|
48
|
+
|
|
49
|
+
Style/RedundantParentheses:
|
|
50
|
+
Enabled: false
|
|
51
|
+
|
|
52
|
+
Style/RedundantBegin:
|
|
53
|
+
Enabled: false
|
|
54
|
+
|
|
55
|
+
Style/RedundantReturn:
|
|
56
|
+
Enabled: false
|
|
57
|
+
|
|
58
|
+
Style/SpecialGlobalVars:
|
|
59
|
+
Enabled: false
|
|
60
|
+
|
|
61
|
+
Style/WordArray:
|
|
62
|
+
Enabled: false
|
data/.travis.yml
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
matrix:
|
|
2
|
+
include:
|
|
3
|
+
- language: ruby
|
|
4
|
+
name: Bundler (rvm 2.5 & bundler)
|
|
5
|
+
rvm: 2.5
|
|
6
|
+
before_install:
|
|
7
|
+
- gem install bundler
|
|
8
|
+
- language: ruby
|
|
9
|
+
name: Bundler (rvm 2.6 & bundler)
|
|
10
|
+
rvm: 2.6
|
|
11
|
+
before_install:
|
|
12
|
+
- gem install bundler
|
|
13
|
+
- language: ruby
|
|
14
|
+
name: Bundler (rvm 2.7 & bundler)
|
|
15
|
+
rvm: 2.7
|
|
16
|
+
before_install:
|
|
17
|
+
- gem install bundler
|
|
18
|
+
- language: ruby
|
|
19
|
+
name: Rubocop (rvm 2.5)
|
|
20
|
+
env: SKIP_INTERPRETER=true
|
|
21
|
+
rvm: 2.5
|
|
22
|
+
before_install:
|
|
23
|
+
- git clone https://github.com/TravisToolbox/rubocop-travis.git
|
|
24
|
+
install:
|
|
25
|
+
- "./rubocop-travis/install.sh"
|
|
26
|
+
script:
|
|
27
|
+
- "./rubocop-travis/scan.sh"
|
|
28
|
+
- language: ruby
|
|
29
|
+
name: Rubocop (rvm 2.6)
|
|
30
|
+
env: SKIP_INTERPRETER=true
|
|
31
|
+
rvm: 2.6
|
|
32
|
+
before_install:
|
|
33
|
+
- git clone https://github.com/TravisToolbox/rubocop-travis.git
|
|
34
|
+
install:
|
|
35
|
+
- "./rubocop-travis/install.sh"
|
|
36
|
+
script:
|
|
37
|
+
- "./rubocop-travis/scan.sh"
|
|
38
|
+
- language: ruby
|
|
39
|
+
name: Rubocop (rvm 2.7)
|
|
40
|
+
env: SKIP_INTERPRETER=true
|
|
41
|
+
rvm: 2.7
|
|
42
|
+
before_install:
|
|
43
|
+
- git clone https://github.com/TravisToolbox/rubocop-travis.git
|
|
44
|
+
install:
|
|
45
|
+
- "./rubocop-travis/install.sh"
|
|
46
|
+
script:
|
|
47
|
+
- "./rubocop-travis/scan.sh"
|
|
48
|
+
- language: ruby
|
|
49
|
+
name: Link Checking (rvm 2.7)
|
|
50
|
+
rvm: 2.7
|
|
51
|
+
env:
|
|
52
|
+
- WHITELIST="https://img.shields.io"
|
|
53
|
+
- EXCLUDE_FILES="CHANGELOG.md"
|
|
54
|
+
before_install:
|
|
55
|
+
- mkdir travis
|
|
56
|
+
- git clone https://github.com/TravisToolbox/awesomebot-travis.git travis/awesomebot
|
|
57
|
+
install:
|
|
58
|
+
- "./travis/awesomebot/install.sh"
|
|
59
|
+
script:
|
|
60
|
+
- "./travis/awesomebot/scan.sh"
|
|
61
|
+
notifications:
|
|
62
|
+
email: false
|
|
63
|
+
slack:
|
|
64
|
+
secure: QeOC43F0nkP7Or6nURy/1stXHL7eigNEnuVnXJ/2KG2gCtnQui18ApvnrWcuG3uP+Jl/4pVreCgy+iDMDi7GaEvEC/Z/vM/Th4oesU6eJ1besw92BM0JcoXkbcLyaHRzEnf6xS49mUtCYSKf1Pf5RjWBn54eu3bXByAujGRbzMACjQ379LGNY1GwbsbyPgn0G/WrqFkmvvsu59MMzXxQaBdNk66iDtQqAbZrvNIgwtmN13u8wjUnq28QcDaJXMzIwopONqnlRQND8z63KIvThQozFGWY+fNbYODytBKQ6qHe9Mn4pbT0M1bBVxYciZ7HLe+e8xm2u+KBvmbZ+1HRHDX60CSdiyK7CzhUV1npnx5DUYfZ+NKzDqcSvhJ3dr00a8ExurKHmaC0ZayCzUljZkaLDnB2iI2s3my8Ss2+q/pywxdU5QXsdTT5OrVkHMVNcNeDA2An1sDr0z0IIQV7gwjoWZckiuvvBRgPrustKX8nF3jEuXO4SK9hTkzNZ4NXdEvjxiGkLX+drwNBjWkGyzY5cLYZ9557XiDxnPpRGuI012/S4v/JGXtM2DqSNBO9B0g88pSEvVN3b04z2dhoNKuATs0Xz4ZNze7N+U1Umutf3kaR3a3kzBqVdnEMeMbjcoDDM66tiH027B7tQjqKFKEForUE4apdSlSwFQsBNpo=
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
This changelog was automatically generated using [Caretaker](https://github.com/WolfAtheneum/covid19) by [Wolf Software](https://github.com/WolfSoftware)
|
|
7
|
+
|
|
8
|
+
### [Unreleased](https://github.com/WolfAtheneum/covid19/compare/0...HEAD)
|
|
9
|
+
|
|
10
|
+
- Fix links and other travis issues [`[815b040]`](https://github.com/WolfAtheneum/covid19/commit/815b04078f795d9e13944e179439ca3fc9c61ddb) [`[TGWolf]`](https://github.com/TGWolf)
|
|
11
|
+
|
|
12
|
+
- Initial commit [`[e83777b]`](https://github.com/WolfAtheneum/covid19/commit/e83777b4b3462b5d31f507a86de3448478d7adb4) [`[TGWolf]`](https://github.com/TGWolf)
|
|
13
|
+
|
data/CODEOWNERS
ADDED
data/Gemfile
ADDED
data/LICENSE.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright © `2016 - 2020` `Wolf Software Limited`
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person
|
|
6
|
+
obtaining a copy of this software and associated documentation
|
|
7
|
+
files (the “Software”), to deal in the Software without
|
|
8
|
+
restriction, including without limitation the rights to use,
|
|
9
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the
|
|
11
|
+
Software is furnished to do so, subject to the following
|
|
12
|
+
conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be
|
|
15
|
+
included in all copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
|
|
18
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
19
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
20
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
21
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
22
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
23
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
24
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
[](https://travis-ci.org/WolfAtheneum/covid19)
|
|
2
|
+
[](LICENSE.md)
|
|
3
|
+
[](https://github.com/WolfAtheneum/covid19/releases/latest)
|
|
4
|
+
[](https://github.com/WolfAtheneum/covid19/releases/latest)
|
|
5
|
+
[](https://github.com/WolfAtheneum/covid19/commits)
|
|
6
|
+
[](https://github.com/WolfAtheneum/covid19/commits/master)
|
|
7
|
+
[](https://github.com/WolfAtheneum)
|
|
8
|
+
[](https://github.com/TGWolf)
|
|
9
|
+
|
|
10
|
+
# Covid19
|
|
11
|
+
|
|
12
|
+
A wrapper for the coronavirus API at https://github.com/ExpDev07/coronavirus-tracker-api.
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
Add this line to your application's Gemfile:
|
|
17
|
+
|
|
18
|
+
```ruby
|
|
19
|
+
gem 'covid19'
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
And then execute:
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
bundle install
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Or install it yourself as:
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
gem install covid19
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Usage
|
|
35
|
+
|
|
36
|
+
Get the latest amount of total confirmed cases, deaths, and recoveries globally:
|
|
37
|
+
|
|
38
|
+
```ruby
|
|
39
|
+
Covid19.latest_stats
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Get case data for all locations with reported cases:
|
|
43
|
+
|
|
44
|
+
```ruby
|
|
45
|
+
Covid19.latest_stats_split_by_country
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Find case data by country code with an optional argument to include timelines:
|
|
49
|
+
|
|
50
|
+
```ruby
|
|
51
|
+
Covid19.latest_stats_by_country_code('GB', true)
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Find case data by location:
|
|
55
|
+
|
|
56
|
+
```ruby
|
|
57
|
+
Covid19.latest_stats_by_country_id(id)
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Error Handling
|
|
61
|
+
|
|
62
|
+
If there are errors trying to talk to the API the class will raise a ```StandardError``` with the appropriate error message.
|
|
63
|
+
|
|
64
|
+
## Command line tool
|
|
65
|
+
|
|
66
|
+
The gem also comes with a command line tool called covid19.
|
|
67
|
+
|
|
68
|
+
```
|
|
69
|
+
Usage: covid19
|
|
70
|
+
-h, --help Display this screen
|
|
71
|
+
-s, --split View the latestest information split by country
|
|
72
|
+
-c, --confirmed Order results by confirmed cases
|
|
73
|
+
-d, --deaths Order results by deaths
|
|
74
|
+
-r, --recovered Order results by recovered numbers
|
|
75
|
+
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Development
|
|
79
|
+
|
|
80
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
81
|
+
|
|
82
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
83
|
+
|
|
84
|
+
### Testing
|
|
85
|
+
|
|
86
|
+
For local testing make sure that you run `bundle exec rspec spec` and then `rake install` to install the gem locally.
|
|
87
|
+
|
|
88
|
+
For further information please refer to the [contributing](https://github.com/WolfSoftware/contributing) documentation.
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'bundler/setup'
|
|
4
|
+
require 'covid19'
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require 'pry'
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require 'irb'
|
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/covid19.gemspec
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
|
+
require 'covid19/version'
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = 'covid19'
|
|
7
|
+
spec.version = Covid19::VERSION
|
|
8
|
+
spec.authors = ['Tim Gurney aka Wolf']
|
|
9
|
+
spec.email = ['wolf@tgwolf.com']
|
|
10
|
+
|
|
11
|
+
spec.summary = 'A wrapper for the coronavirus API at https://github.com/ExpDev07/coronavirus-tracker-api.'
|
|
12
|
+
spec.description = 'A wrapper for the coronavirus API at https://github.com/ExpDev07/coronavirus-tracker-api.'
|
|
13
|
+
spec.homepage = 'https://github.com/WolfAtheneum/covid19'
|
|
14
|
+
spec.license = 'MIT'
|
|
15
|
+
|
|
16
|
+
spec.files = `git ls-files`.split($/)
|
|
17
|
+
|
|
18
|
+
spec.bindir = 'exe'
|
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
20
|
+
spec.require_paths = ['lib']
|
|
21
|
+
|
|
22
|
+
spec.required_ruby_version = '>= 2.5'
|
|
23
|
+
|
|
24
|
+
spec.add_development_dependency 'bundler', '~> 2'
|
|
25
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
|
26
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
|
27
|
+
spec.add_development_dependency 'terminal-table', '~> 1.8'
|
|
28
|
+
|
|
29
|
+
spec.add_runtime_dependency 'terminal-table', '~> 1.8'
|
|
30
|
+
end
|
data/exe/covid19
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
$LOAD_PATH.unshift('./lib')
|
|
4
|
+
|
|
5
|
+
require 'optparse'
|
|
6
|
+
require 'covid19'
|
|
7
|
+
require 'terminal-table'
|
|
8
|
+
|
|
9
|
+
# -------------------------------------------------------------------------------- #
|
|
10
|
+
# Format Global Stats #
|
|
11
|
+
# -------------------------------------------------------------------------------- #
|
|
12
|
+
# Create a nice table view of the latest global stats. #
|
|
13
|
+
# -------------------------------------------------------------------------------- #
|
|
14
|
+
|
|
15
|
+
def format_latest_stats(results)
|
|
16
|
+
formatted = []
|
|
17
|
+
results['latest'].each do |key, value|
|
|
18
|
+
formatted << [key, value]
|
|
19
|
+
end
|
|
20
|
+
puts Terminal::Table.new :title => 'Latest Global Statistics', :rows => formatted, :style => { :width => 80 }
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# -------------------------------------------------------------------------------- #
|
|
24
|
+
# Format Country Stats #
|
|
25
|
+
# -------------------------------------------------------------------------------- #
|
|
26
|
+
# Create a nice table view of the latest country stats. #
|
|
27
|
+
# -------------------------------------------------------------------------------- #
|
|
28
|
+
def format_latest_country_stats(results, options = {})
|
|
29
|
+
processed = {}
|
|
30
|
+
|
|
31
|
+
results['locations'].each do |item|
|
|
32
|
+
country_code = item['country_code'].to_s
|
|
33
|
+
|
|
34
|
+
if processed[country_code]
|
|
35
|
+
confirmed = processed[country_code]['confirmed'] + item['latest']['confirmed']
|
|
36
|
+
deaths = processed[country_code]['deaths'] + item['latest']['deaths']
|
|
37
|
+
recovered = processed[country_code]['recovered'] + item['latest']['recovered']
|
|
38
|
+
else
|
|
39
|
+
confirmed = item['latest']['confirmed']
|
|
40
|
+
deaths = item['latest']['deaths']
|
|
41
|
+
recovered = item['latest']['recovered']
|
|
42
|
+
end
|
|
43
|
+
processed[country_code] = { 'country' => item['country'], 'country_code' => country_code, 'id' => item['id'], 'confirmed' => confirmed, 'deaths' => deaths, 'recovered' => recovered }
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
sorted = []
|
|
47
|
+
processed.each do |_key, value|
|
|
48
|
+
sorted << value
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
sorted = sorted.sort_by { |k| k['country'] }
|
|
52
|
+
sorted = sorted.sort_by { |k| k['confirmed'] }.reverse if options[:confirmed]
|
|
53
|
+
sorted = sorted.sort_by { |k| k['deaths'] }.reverse if options[:deaths]
|
|
54
|
+
sorted = sorted.sort_by { |k| k['recovered'] }.reverse if options[:recovered]
|
|
55
|
+
|
|
56
|
+
formatted = []
|
|
57
|
+
sorted.each do |item|
|
|
58
|
+
formatted << [item['country'], item['country_code'], item['id'], item['confirmed'], item['deaths'], item['recovered']]
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
table = Terminal::Table.new :title => 'Latest Statistics by Country', :headings => ['Country', 'Code', 'ID', 'Confirmed', 'Deaths', 'Recovered'], :rows => formatted, :style => { :padding_left => 2, :padding_right => 2 }
|
|
62
|
+
table.align_column(1, :center)
|
|
63
|
+
table.align_column(2, :right)
|
|
64
|
+
table.align_column(3, :right)
|
|
65
|
+
table.align_column(4, :right)
|
|
66
|
+
table.align_column(5, :right)
|
|
67
|
+
|
|
68
|
+
puts table
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# -------------------------------------------------------------------------------- #
|
|
72
|
+
# Get Covid 19 Stats #
|
|
73
|
+
# -------------------------------------------------------------------------------- #
|
|
74
|
+
# This function will take the input arguments and then request the stats. #
|
|
75
|
+
# -------------------------------------------------------------------------------- #
|
|
76
|
+
|
|
77
|
+
def get_covid19_stats(options)
|
|
78
|
+
begin
|
|
79
|
+
format_latest_stats(Covid19.latest_stats) if options[:latest]
|
|
80
|
+
format_latest_country_stats(Covid19.latest_stats_split_by_country, options) unless options[:latest]
|
|
81
|
+
rescue StandardError => e
|
|
82
|
+
puts "Error: #{e}"
|
|
83
|
+
puts e.backtrace
|
|
84
|
+
exit(1)
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# -------------------------------------------------------------------------------- #
|
|
89
|
+
# Process Arguments #
|
|
90
|
+
# -------------------------------------------------------------------------------- #
|
|
91
|
+
# This function will process the input from the command line and work out what it #
|
|
92
|
+
# is that the user wants to see. #
|
|
93
|
+
# #
|
|
94
|
+
# This is the main processing function where all the processing logic is handled. #
|
|
95
|
+
# -------------------------------------------------------------------------------- #
|
|
96
|
+
|
|
97
|
+
def process_arguments
|
|
98
|
+
options = { :latest => true }
|
|
99
|
+
# Enforce the presence of
|
|
100
|
+
mandatory = %I[]
|
|
101
|
+
|
|
102
|
+
optparse = OptionParser.new do |opts|
|
|
103
|
+
opts.banner = "Usage: #{$PROGRAM_NAME}"
|
|
104
|
+
|
|
105
|
+
opts.on('-h', '--help', 'Display this screen') do
|
|
106
|
+
puts opts
|
|
107
|
+
exit(1)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
opts.on('-s', '--split', 'View the latestest information for all locations') do
|
|
111
|
+
options[:latest] = false
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
opts.on('-c', '--confirmed', 'Order results by confirmed cases') do
|
|
115
|
+
options[:confirmed] = true
|
|
116
|
+
options[:deaths] = false
|
|
117
|
+
options[:recovered] = false
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
opts.on('-d', '--deaths', 'Order results by deaths') do
|
|
121
|
+
options[:confirmed] = false
|
|
122
|
+
options[:deaths] = true
|
|
123
|
+
options[:recovered] = false
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
opts.on('-r', '--recovered', 'Order results by recovered numbers') do
|
|
127
|
+
options[:confirmed] = false
|
|
128
|
+
options[:deaths] = false
|
|
129
|
+
options[:recovered] = true
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
begin
|
|
134
|
+
optparse.parse!
|
|
135
|
+
missing = mandatory.select { |param| options[param].nil? }
|
|
136
|
+
raise OptionParser::MissingArgument.new(missing.join(', ')) unless missing.empty?
|
|
137
|
+
rescue OptionParser::InvalidOption, OptionParser::MissingArgument => e
|
|
138
|
+
puts e.to_s
|
|
139
|
+
puts optparse
|
|
140
|
+
exit
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
exit 0 if get_covid19_stats(options)
|
|
144
|
+
|
|
145
|
+
exit 1
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
# -------------------------------------------------------------------------------- #
|
|
149
|
+
# Main() #
|
|
150
|
+
# -------------------------------------------------------------------------------- #
|
|
151
|
+
# The main function where all of the heavy lifting and script config is done. #
|
|
152
|
+
# -------------------------------------------------------------------------------- #
|
|
153
|
+
|
|
154
|
+
def main
|
|
155
|
+
process_arguments
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
main
|
|
159
|
+
|
|
160
|
+
# -------------------------------------------------------------------------------- #
|
|
161
|
+
# End of Script #
|
|
162
|
+
# -------------------------------------------------------------------------------- #
|
|
163
|
+
# This is the end - nothing more to see here. #
|
|
164
|
+
# -------------------------------------------------------------------------------- #
|
data/lib/covid19.rb
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
require 'covid19/version'
|
|
2
|
+
|
|
3
|
+
require 'json'
|
|
4
|
+
require 'net/http'
|
|
5
|
+
|
|
6
|
+
#
|
|
7
|
+
# To Follow
|
|
8
|
+
#
|
|
9
|
+
class Covid19
|
|
10
|
+
API_URL = 'https://coronavirus-tracker-api.herokuapp.com/v2/'.freeze
|
|
11
|
+
|
|
12
|
+
class << self
|
|
13
|
+
def latest_stats
|
|
14
|
+
return retrieve_api_data('latest')
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def latest_stats_split_by_country
|
|
18
|
+
return retrieve_api_data('locations')
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def latest_stats_by_country_code(country_code, with_timelines = false)
|
|
22
|
+
timelines = with_timelines ? '&timelines=true' : ''
|
|
23
|
+
return retrieve_api_data("locations?country_code=#{country_code.upcase}#{timelines}")
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def latest_stats_by_country_id(id)
|
|
27
|
+
return retrieve_api_data("locations/#{id}")
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
private
|
|
31
|
+
|
|
32
|
+
def retrieve_api_data(uri)
|
|
33
|
+
url = URI("#{API_URL}#{uri}")
|
|
34
|
+
|
|
35
|
+
begin
|
|
36
|
+
response = Net::HTTP.get(url)
|
|
37
|
+
return JSON.parse(response)
|
|
38
|
+
rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e
|
|
39
|
+
raise StandardError.new(e.to_s)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
require 'bundler/setup'
|
|
2
|
+
require 'covid19'
|
|
3
|
+
|
|
4
|
+
RSpec.configure do |config|
|
|
5
|
+
# Enable flags like --only-failures and --next-failure
|
|
6
|
+
config.example_status_persistence_file_path = '.rspec_status'
|
|
7
|
+
|
|
8
|
+
# Disable RSpec exposing methods globally on `Module` and `main`
|
|
9
|
+
config.disable_monkey_patching!
|
|
10
|
+
|
|
11
|
+
config.expect_with :rspec do |c|
|
|
12
|
+
c.syntax = :expect
|
|
13
|
+
end
|
|
14
|
+
end
|
data/stale.yml
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Number of days of inactivity before an issue becomes stale
|
|
2
|
+
daysUntilStale: 60
|
|
3
|
+
# Number of days of inactivity before a stale issue is closed
|
|
4
|
+
daysUntilClose: 7
|
|
5
|
+
# Issues with these labels will never be considered stale
|
|
6
|
+
exemptLabels:
|
|
7
|
+
- pinned
|
|
8
|
+
- security
|
|
9
|
+
# Label to use when marking an issue as stale
|
|
10
|
+
staleLabel: wontfix
|
|
11
|
+
# Comment to post when marking an issue as stale. Set to `false` to disable
|
|
12
|
+
markComment: >
|
|
13
|
+
This issue has been automatically marked as stale because it has not had
|
|
14
|
+
recent activity. It will be closed if no further activity occurs. Thank you
|
|
15
|
+
for your contributions.
|
|
16
|
+
# Comment to post when closing a stale issue. Set to `false` to disable
|
|
17
|
+
closeComment: true
|
data/testing/covid19
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
$LOAD_PATH.unshift('./lib')
|
|
4
|
+
|
|
5
|
+
require 'bundler/setup'
|
|
6
|
+
require 'optparse'
|
|
7
|
+
require 'covid19'
|
|
8
|
+
require 'terminal-table'
|
|
9
|
+
|
|
10
|
+
# -------------------------------------------------------------------------------- #
|
|
11
|
+
# Format Global Stats #
|
|
12
|
+
# -------------------------------------------------------------------------------- #
|
|
13
|
+
# Create a nice table view of the latest global stats. #
|
|
14
|
+
# -------------------------------------------------------------------------------- #
|
|
15
|
+
|
|
16
|
+
def format_latest_stats(results)
|
|
17
|
+
formatted = []
|
|
18
|
+
results['latest'].each do |key, value|
|
|
19
|
+
formatted << [key, value]
|
|
20
|
+
end
|
|
21
|
+
puts Terminal::Table.new :title => 'Latest Global Statistics', :rows => formatted, :style => { :width => 80 }
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# -------------------------------------------------------------------------------- #
|
|
25
|
+
# Format Country Stats #
|
|
26
|
+
# -------------------------------------------------------------------------------- #
|
|
27
|
+
# Create a nice table view of the latest country stats. #
|
|
28
|
+
# -------------------------------------------------------------------------------- #
|
|
29
|
+
def format_latest_country_stats(results, options = {})
|
|
30
|
+
processed = {}
|
|
31
|
+
|
|
32
|
+
results['locations'].each do |item|
|
|
33
|
+
country_code = item['country_code'].to_s
|
|
34
|
+
|
|
35
|
+
if processed[country_code]
|
|
36
|
+
confirmed = processed[country_code]['confirmed'] + item['latest']['confirmed']
|
|
37
|
+
deaths = processed[country_code]['deaths'] + item['latest']['deaths']
|
|
38
|
+
recovered = processed[country_code]['recovered'] + item['latest']['recovered']
|
|
39
|
+
else
|
|
40
|
+
confirmed = item['latest']['confirmed']
|
|
41
|
+
deaths = item['latest']['deaths']
|
|
42
|
+
recovered = item['latest']['recovered']
|
|
43
|
+
end
|
|
44
|
+
processed[country_code] = { 'country' => item['country'], 'country_code' => country_code, 'id' => item['id'], 'confirmed' => confirmed, 'deaths' => deaths, 'recovered' => recovered }
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
sorted = []
|
|
48
|
+
processed.each do |_key, value|
|
|
49
|
+
sorted << value
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
sorted = sorted.sort_by { |k| k['country'] }
|
|
53
|
+
sorted = sorted.sort_by { |k| k['confirmed'] }.reverse if options[:confirmed]
|
|
54
|
+
sorted = sorted.sort_by { |k| k['deaths'] }.reverse if options[:deaths]
|
|
55
|
+
sorted = sorted.sort_by { |k| k['recovered'] }.reverse if options[:recovered]
|
|
56
|
+
|
|
57
|
+
formatted = []
|
|
58
|
+
sorted.each do |item|
|
|
59
|
+
formatted << [item['country'], item['country_code'], item['id'], item['confirmed'], item['deaths'], item['recovered']]
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
table = Terminal::Table.new :title => 'Latest Statistics by Country', :headings => ['Country', 'Code', 'ID', 'Confirmed', 'Deaths', 'Recovered'], :rows => formatted, :style => { :padding_left => 2, :padding_right => 2 }
|
|
63
|
+
table.align_column(1, :center)
|
|
64
|
+
table.align_column(2, :right)
|
|
65
|
+
table.align_column(3, :right)
|
|
66
|
+
table.align_column(4, :right)
|
|
67
|
+
table.align_column(5, :right)
|
|
68
|
+
|
|
69
|
+
puts table
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# -------------------------------------------------------------------------------- #
|
|
73
|
+
# Get Covid 19 Stats #
|
|
74
|
+
# -------------------------------------------------------------------------------- #
|
|
75
|
+
# This function will take the input arguments and then request the stats. #
|
|
76
|
+
# -------------------------------------------------------------------------------- #
|
|
77
|
+
|
|
78
|
+
def get_covid19_stats(options)
|
|
79
|
+
begin
|
|
80
|
+
format_latest_stats(Covid19.latest_stats) if options[:latest]
|
|
81
|
+
format_latest_country_stats(Covid19.latest_stats_split_by_country, options) unless options[:latest]
|
|
82
|
+
rescue StandardError => e
|
|
83
|
+
puts "Error: #{e}"
|
|
84
|
+
puts e.backtrace
|
|
85
|
+
exit(1)
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# -------------------------------------------------------------------------------- #
|
|
90
|
+
# Process Arguments #
|
|
91
|
+
# -------------------------------------------------------------------------------- #
|
|
92
|
+
# This function will process the input from the command line and work out what it #
|
|
93
|
+
# is that the user wants to see. #
|
|
94
|
+
# #
|
|
95
|
+
# This is the main processing function where all the processing logic is handled. #
|
|
96
|
+
# -------------------------------------------------------------------------------- #
|
|
97
|
+
|
|
98
|
+
def process_arguments
|
|
99
|
+
options = { :latest => true }
|
|
100
|
+
# Enforce the presence of
|
|
101
|
+
mandatory = %I[]
|
|
102
|
+
|
|
103
|
+
optparse = OptionParser.new do |opts|
|
|
104
|
+
opts.banner = "Usage: #{$PROGRAM_NAME}"
|
|
105
|
+
|
|
106
|
+
opts.on('-h', '--help', 'Display this screen') do
|
|
107
|
+
puts opts
|
|
108
|
+
exit(1)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
opts.on('-s', '--split', 'View the latestest information for all locations') do
|
|
112
|
+
options[:latest] = false
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
opts.on('-c', '--confirmed', 'Order results by confirmed cases') do
|
|
116
|
+
options[:confirmed] = true
|
|
117
|
+
options[:deaths] = false
|
|
118
|
+
options[:recovered] = false
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
opts.on('-d', '--deaths', 'Order results by deaths') do
|
|
122
|
+
options[:confirmed] = false
|
|
123
|
+
options[:deaths] = true
|
|
124
|
+
options[:recovered] = false
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
opts.on('-r', '--recovered', 'Order results by recovered numbers') do
|
|
128
|
+
options[:confirmed] = false
|
|
129
|
+
options[:deaths] = false
|
|
130
|
+
options[:recovered] = true
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
begin
|
|
135
|
+
optparse.parse!
|
|
136
|
+
missing = mandatory.select { |param| options[param].nil? }
|
|
137
|
+
raise OptionParser::MissingArgument.new(missing.join(', ')) unless missing.empty?
|
|
138
|
+
rescue OptionParser::InvalidOption, OptionParser::MissingArgument => e
|
|
139
|
+
puts e.to_s
|
|
140
|
+
puts optparse
|
|
141
|
+
exit
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
exit 0 if get_covid19_stats(options)
|
|
145
|
+
|
|
146
|
+
exit 1
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
# -------------------------------------------------------------------------------- #
|
|
150
|
+
# Main() #
|
|
151
|
+
# -------------------------------------------------------------------------------- #
|
|
152
|
+
# The main function where all of the heavy lifting and script config is done. #
|
|
153
|
+
# -------------------------------------------------------------------------------- #
|
|
154
|
+
|
|
155
|
+
def main
|
|
156
|
+
process_arguments
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
main
|
|
160
|
+
|
|
161
|
+
# -------------------------------------------------------------------------------- #
|
|
162
|
+
# End of Script #
|
|
163
|
+
# -------------------------------------------------------------------------------- #
|
|
164
|
+
# This is the end - nothing more to see here. #
|
|
165
|
+
# -------------------------------------------------------------------------------- #
|
metadata
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: covid19
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Tim Gurney aka Wolf
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2020-03-19 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '2'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '2'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '13.0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '13.0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rspec
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '3.0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '3.0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: terminal-table
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '1.8'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '1.8'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: terminal-table
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '1.8'
|
|
76
|
+
type: :runtime
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '1.8'
|
|
83
|
+
description: A wrapper for the coronavirus API at https://github.com/ExpDev07/coronavirus-tracker-api.
|
|
84
|
+
email:
|
|
85
|
+
- wolf@tgwolf.com
|
|
86
|
+
executables:
|
|
87
|
+
- covid19
|
|
88
|
+
extensions: []
|
|
89
|
+
extra_rdoc_files: []
|
|
90
|
+
files:
|
|
91
|
+
- ".gitattributes"
|
|
92
|
+
- ".gitignore"
|
|
93
|
+
- ".rspec"
|
|
94
|
+
- ".rubocop.yml"
|
|
95
|
+
- ".travis.yml"
|
|
96
|
+
- CHANGELOG.md
|
|
97
|
+
- CODEOWNERS
|
|
98
|
+
- Gemfile
|
|
99
|
+
- LICENSE.md
|
|
100
|
+
- README.md
|
|
101
|
+
- Rakefile
|
|
102
|
+
- bin/console
|
|
103
|
+
- bin/setup
|
|
104
|
+
- covid19.gemspec
|
|
105
|
+
- exe/covid19
|
|
106
|
+
- lib/covid19.rb
|
|
107
|
+
- lib/covid19/version.rb
|
|
108
|
+
- spec/covid19_spec.rb
|
|
109
|
+
- spec/spec_helper.rb
|
|
110
|
+
- stale.yml
|
|
111
|
+
- testing/covid19
|
|
112
|
+
homepage: https://github.com/WolfAtheneum/covid19
|
|
113
|
+
licenses:
|
|
114
|
+
- MIT
|
|
115
|
+
metadata: {}
|
|
116
|
+
post_install_message:
|
|
117
|
+
rdoc_options: []
|
|
118
|
+
require_paths:
|
|
119
|
+
- lib
|
|
120
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
121
|
+
requirements:
|
|
122
|
+
- - ">="
|
|
123
|
+
- !ruby/object:Gem::Version
|
|
124
|
+
version: '2.5'
|
|
125
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
126
|
+
requirements:
|
|
127
|
+
- - ">="
|
|
128
|
+
- !ruby/object:Gem::Version
|
|
129
|
+
version: '0'
|
|
130
|
+
requirements: []
|
|
131
|
+
rubygems_version: 3.0.3
|
|
132
|
+
signing_key:
|
|
133
|
+
specification_version: 4
|
|
134
|
+
summary: A wrapper for the coronavirus API at https://github.com/ExpDev07/coronavirus-tracker-api.
|
|
135
|
+
test_files: []
|