playwhe 0.1.0 → 0.2.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/.gitignore +1 -16
- data/Gemfile +1 -2
- data/LICENSE +17 -18
- data/README.md +98 -89
- data/Rakefile +9 -2
- data/bin/playwhe +99 -74
- data/lib/playwhe.rb +76 -133
- data/lib/playwhe/fetcher.rb +25 -0
- data/lib/playwhe/get.rb +214 -0
- data/lib/playwhe/http.rb +39 -0
- data/lib/playwhe/parser.rb +15 -0
- data/lib/playwhe/result.rb +119 -0
- data/lib/playwhe/settings.rb +15 -0
- data/lib/playwhe/util.rb +11 -0
- data/lib/playwhe/version.rb +1 -1
- data/playwhe.gemspec +32 -24
- data/test/playwhe/fetcher_test.rb +72 -0
- data/test/playwhe/get_test.rb +187 -0
- data/test/playwhe/http/adapter_test.rb +46 -0
- data/test/playwhe/http/response_test.rb +39 -0
- data/test/playwhe/parser_test.rb +34 -0
- data/test/playwhe/result_test.rb +158 -0
- data/test/playwhe/settings_test.rb +13 -0
- data/test/playwhe/util_test.rb +37 -0
- data/test/test_helper.rb +6 -0
- metadata +97 -45
- data/data/playwhe.db +0 -0
- data/lib/playwhe/storage.rb +0 -109
- data/lib/playwhe/storage/models.rb +0 -92
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9d783ee5066f3954ae5f3afbfedbaac7e963f14b
|
4
|
+
data.tar.gz: ef9392125d15a142ca70a5a3a29a6d2b678ea96a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 26252985bd2b160a75c1127a1cb1d48d1bbc07832b973402bc1d115a08008ebd8e641cc371b287a4a50cf587f06c5df6917e110a0c53aae5d8be85604d8ac14d
|
7
|
+
data.tar.gz: ac4941653662988a5570b7fdc7c15bb4ea80671ae8c4fd0e78184d541d7552263c1776e6b31162901f6b7b4cc1e55889ddb7e71f63eeede34b1ad7b71f5f6076
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/LICENSE
CHANGED
@@ -1,22 +1,21 @@
|
|
1
|
-
Copyright (c) 2012 Dwayne R. Crooks
|
2
|
-
|
3
1
|
MIT License
|
4
2
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
the
|
3
|
+
Copyright (c) 2016 Dwayne Crooks
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
12
11
|
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
15
14
|
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
OF
|
22
|
-
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
CHANGED
@@ -1,106 +1,115 @@
|
|
1
|
-
|
1
|
+
## About
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
The gem provides a ruby API and script for retrieving and storing Play Whe
|
6
|
-
results from the National Lotteries Control Board (NLCB) website at
|
7
|
-
http://www.nlcb.co.tt/.
|
8
|
-
|
9
|
-
## Quick Start
|
10
|
-
|
11
|
-
$ gem install playwhe
|
12
|
-
$ playwhe -b && playwhe -u
|
13
|
-
|
14
|
-
$ echo Fetch results for October, 2010
|
15
|
-
$ playwhe -f 2010-10
|
16
|
-
|
17
|
-
$ echo Fetch results for 10 October, 2010
|
18
|
-
$ playwhe -f 2010-10-10
|
3
|
+
playwhe is a Ruby library for retrieving Play Whe results from the [National Lotteries
|
4
|
+
Control Board](http://www.nlcb.co.tt/) (NLCB) website.
|
19
5
|
|
20
6
|
## Installation
|
21
7
|
|
22
8
|
Add this line to your application's Gemfile:
|
23
9
|
|
24
|
-
|
10
|
+
```ruby
|
11
|
+
gem "playwhe"
|
12
|
+
```
|
25
13
|
|
26
14
|
And then execute:
|
27
15
|
|
28
|
-
|
16
|
+
```bash
|
17
|
+
$ bundle
|
18
|
+
```
|
29
19
|
|
30
20
|
Or install it yourself as:
|
31
21
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
After installation you will have access to both the library and an executable.
|
37
|
-
|
38
|
-
To use the library, simply require **playwhe** and you would be able to retrieve
|
39
|
-
Play Whe results in your code. If you need a way to persist those results, then
|
40
|
-
you can also require **playwhe/storage**.
|
41
|
-
|
42
|
-
The executable is called **playwhe** and it allows you to
|
43
|
-
|
44
|
-
1. Setup a directory with a database of Play Whe results.
|
45
|
-
|
46
|
-
$ playwhe --bootstrap # or playwhe -b
|
47
|
-
|
48
|
-
2. Create and initialize a database for storing Play Whe results.
|
49
|
-
|
50
|
-
$ playwhe --create # or playwhe -c
|
51
|
-
|
52
|
-
3. Update a database with the latest Play Whe results.
|
53
|
-
|
54
|
-
$ playwhe --update # or playwhe -u
|
55
|
-
|
56
|
-
Note that you can create and update one after the other with the following
|
57
|
-
command.
|
22
|
+
```bash
|
23
|
+
$ gem install playwhe
|
24
|
+
```
|
58
25
|
|
59
|
-
|
26
|
+
Inside of your Ruby program do:
|
60
27
|
|
61
|
-
|
28
|
+
```ruby
|
29
|
+
require "playwhe"
|
30
|
+
```
|
62
31
|
|
63
|
-
|
64
|
-
$ playwhe --fetch 2012-04 # or playwhe -f 2012-04
|
32
|
+
... to pull it in as a dependency.
|
65
33
|
|
66
|
-
|
67
|
-
|
68
|
-
$ echo Fetch results for 2nd April, 2012
|
69
|
-
$ playwhe --fetch 2012-04-02 # or playwhe -f 2012-04-02
|
70
|
-
|
71
|
-
Note that the fetch is done using a local database of results. So, you must
|
72
|
-
have created and updated your own local database before running this command.
|
73
|
-
|
74
|
-
## Dev Notes
|
75
|
-
|
76
|
-
How to access the library?
|
77
|
-
|
78
|
-
$ irb -Ilib --simple-prompt
|
79
|
-
>> require 'playwhe'
|
80
|
-
>> require 'playwhe/storage'
|
81
|
-
|
82
|
-
How to update **data/playwhe.db**?
|
83
|
-
|
84
|
-
>> PlayWhe::Storage.update './data'
|
85
|
-
|
86
|
-
How to update **data/playwhe.db** using **bin/playwhe**?
|
87
|
-
|
88
|
-
$ ruby -Ilib ./bin/playwhe -l debug -u ./data
|
89
|
-
|
90
|
-
How to access the data in **data/playwhe.db**?
|
91
|
-
|
92
|
-
>> PlayWhe::Storage.connect './data/playwhe.db'
|
93
|
-
>> PlayWhe::Storage::Result.first # for e.g. retrieve the first result
|
94
|
-
|
95
|
-
How to access the data in **data/playwhe.db** using **bin/playwhe**?
|
96
|
-
|
97
|
-
$ ruby -Ilib ./bin/playwhe -f 1994-07-04 ./data
|
98
|
-
|
99
|
-
## Help
|
100
|
-
|
101
|
-
For help using the executable, try
|
102
|
-
|
103
|
-
$ playwhe --help # or playwhe -h
|
34
|
+
## Usage
|
104
35
|
|
105
|
-
|
106
|
-
|
36
|
+
This gem comes with a CLI called `playwhe`. Below are some examples of its usage.
|
37
|
+
|
38
|
+
List the 4 most recent results in descending order:
|
39
|
+
|
40
|
+
```bash
|
41
|
+
$ playwhe
|
42
|
+
# or
|
43
|
+
$ playwhe --most-recent 4
|
44
|
+
# or
|
45
|
+
$ playwhe --most-recent --order desc
|
46
|
+
15253,2016-07-02,29,PM
|
47
|
+
15252,2016-07-02,30,AN
|
48
|
+
15251,2016-07-02,31,AM
|
49
|
+
15250,2016-07-02,29,EM
|
50
|
+
```
|
51
|
+
|
52
|
+
List the 4 most recent results in ascending order:
|
53
|
+
|
54
|
+
```bash
|
55
|
+
$ playwhe --order asc
|
56
|
+
15250,2016-07-02,29,EM
|
57
|
+
15251,2016-07-02,31,AM
|
58
|
+
15252,2016-07-02,30,AN
|
59
|
+
15253,2016-07-02,29,PM
|
60
|
+
```
|
61
|
+
|
62
|
+
List the 8 least recent results in ascending order:
|
63
|
+
|
64
|
+
```bash
|
65
|
+
$ playwhe --least-recent 8
|
66
|
+
1,1994-07-04,15,AM
|
67
|
+
2,1994-07-04,11,PM
|
68
|
+
3,1994-07-05,36,AM
|
69
|
+
4,1994-07-05,31,PM
|
70
|
+
5,1994-07-06,12,AM
|
71
|
+
6,1994-07-06,36,PM
|
72
|
+
7,1994-07-07,6,AM
|
73
|
+
8,1994-07-07,23,PM
|
74
|
+
```
|
75
|
+
|
76
|
+
List all the results for the year 2015 in ascending order:
|
77
|
+
|
78
|
+
```bash
|
79
|
+
$ playwhe 2015
|
80
|
+
13562,2015-01-01,29,EM
|
81
|
+
13563,2015-01-01,29,AM
|
82
|
+
13564,2015-01-01,1,PM
|
83
|
+
...
|
84
|
+
14630,2015-12-31,15,EM
|
85
|
+
14631,2015-12-31,13,AM
|
86
|
+
14632,2015-12-31,28,AN
|
87
|
+
14633,2015-12-31,27,PM
|
88
|
+
```
|
89
|
+
|
90
|
+
List all the results for April 2016 in descending order:
|
91
|
+
|
92
|
+
```bash
|
93
|
+
$ playwhe 2016 4 --order desc
|
94
|
+
15041,2016-04-30,3,PM
|
95
|
+
15040,2016-04-30,6,AN
|
96
|
+
15039,2016-04-30,31,AM
|
97
|
+
15038,2016-04-30,27,EM
|
98
|
+
...
|
99
|
+
14941,2016-04-01,3,PM
|
100
|
+
14940,2016-04-01,16,AN
|
101
|
+
14939,2016-04-01,14,AM
|
102
|
+
14938,2016-04-01,31,EM
|
103
|
+
```
|
104
|
+
|
105
|
+
List all the results for October 10th, 2008 in ascending order:
|
106
|
+
|
107
|
+
```bash
|
108
|
+
$ playwhe 2008 10 10
|
109
|
+
8775,2008-10-10,31,AM
|
110
|
+
8776,2008-10-10,12,PM
|
111
|
+
```
|
112
|
+
|
113
|
+
## Copyright
|
114
|
+
|
115
|
+
Copyright (c) 2016 Dwayne Crooks. See [LICENSE](/LICENSE) for further details.
|
data/Rakefile
CHANGED
data/bin/playwhe
CHANGED
@@ -1,88 +1,113 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
banner <<-
|
12
|
-
|
13
|
-
|
14
|
-
Usage:
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
3
|
+
require "optparse"
|
4
|
+
|
5
|
+
require_relative "../lib/playwhe"
|
6
|
+
|
7
|
+
options = {}
|
8
|
+
|
9
|
+
option_parser = OptionParser.new do |opts|
|
10
|
+
executable_name = File.basename($PROGRAM_NAME)
|
11
|
+
opts.banner = <<-BANNER
|
12
|
+
Display Play Whe results
|
13
|
+
|
14
|
+
Usage: #{executable_name} [args] [options]
|
15
|
+
|
16
|
+
Arguments:
|
17
|
+
\t<year>
|
18
|
+
\t<year> <month>
|
19
|
+
\t<year> <month> <day>
|
20
|
+
|
21
|
+
Options:
|
22
|
+
BANNER
|
23
|
+
|
24
|
+
opts.on("--most-recent N", Integer, "List the N (>= 1) most recent results") do |n|
|
25
|
+
if n >= 1
|
26
|
+
options[:most_recent] = n
|
27
|
+
else
|
28
|
+
raise ArgumentError, "invalid argument: --most-recent #{n}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
opts.on("--least-recent N", Integer, "List the N (>= 1) least recent results") do |n|
|
33
|
+
if n >= 1
|
34
|
+
options[:least_recent] = n
|
35
|
+
else
|
36
|
+
raise ArgumentError, "invalid argument: --least-recent #{n}"
|
37
|
+
end
|
38
|
+
end
|
25
39
|
|
26
|
-
|
40
|
+
opts.on("--order asc|desc", %i(asc desc), "List in ascending or descending order") do |order|
|
41
|
+
options[:order] = order
|
42
|
+
end
|
27
43
|
|
28
|
-
|
29
|
-
|
30
|
-
|
44
|
+
opts.on("-v", "--version", "Show version information, then exit") do
|
45
|
+
puts PlayWhe::VERSION
|
46
|
+
exit
|
47
|
+
end
|
48
|
+
|
49
|
+
opts.on("-h", "--help", "Show this help, then exit") do
|
50
|
+
puts opts
|
51
|
+
exit
|
52
|
+
end
|
31
53
|
end
|
32
54
|
|
33
55
|
begin
|
34
|
-
|
56
|
+
option_parser.parse!
|
57
|
+
rescue => e
|
58
|
+
STDERR.puts "Please check your options/arguments"
|
59
|
+
STDERR.puts "Error: #{e.message}"
|
60
|
+
exit 1
|
61
|
+
end
|
35
62
|
|
36
|
-
|
37
|
-
|
38
|
-
|
63
|
+
def as_csv(results)
|
64
|
+
results.map(&:to_s).join("\n")
|
65
|
+
end
|
39
66
|
|
40
|
-
|
41
|
-
|
67
|
+
def get_results(args, options)
|
68
|
+
if options.key?(:most_recent)
|
69
|
+
PlayWhe.get.most_recent(limit: options[:most_recent], order: options.fetch(:order, :desc))
|
70
|
+
elsif options.key?(:least_recent)
|
71
|
+
PlayWhe.get.least_recent(limit: options[:least_recent], order: options.fetch(:order, :asc))
|
72
|
+
elsif args.any?
|
73
|
+
nargs = args.length
|
74
|
+
order = options.fetch(:order, :asc)
|
75
|
+
|
76
|
+
if nargs == 1
|
77
|
+
year = args[0].to_i
|
78
|
+
PlayWhe.get.results_for_year(Date.new(year), order: order)
|
79
|
+
elsif nargs == 2
|
80
|
+
year = args[0].to_i
|
81
|
+
month = args[1].to_i
|
82
|
+
PlayWhe.get.results_for_month(Date.new(year, month), order: order)
|
83
|
+
elsif nargs == 3
|
84
|
+
year = args[0].to_i
|
85
|
+
month = args[1].to_i
|
86
|
+
day = args[2].to_i
|
87
|
+
PlayWhe.get.results_for_day(Date.new(year, month, day), order: order)
|
42
88
|
else
|
43
|
-
|
44
|
-
FileUtils.cp(data, path, :verbose => true)
|
45
|
-
|
46
|
-
puts "You're all setup now. Have fun!"
|
89
|
+
raise ArgumentError, "Too many arguments"
|
47
90
|
end
|
48
91
|
else
|
49
|
-
PlayWhe
|
50
|
-
PlayWhe::Storage.update(path, opts[:log_level]) if opts[:update]
|
51
|
-
|
52
|
-
if opts[:fetch]
|
53
|
-
PlayWhe::Storage.connect(File.join(path, 'playwhe.db'), opts[:log_level])
|
54
|
-
|
55
|
-
year = match[1].to_i
|
56
|
-
month = match[2].to_i
|
57
|
-
|
58
|
-
if match[3].nil?
|
59
|
-
# get results for a given month
|
60
|
-
begin
|
61
|
-
results = PlayWhe::Storage::Result.all_by_month(year, month).reverse
|
62
|
-
rescue
|
63
|
-
puts "Sorry, we encountered an error. Please check the date you entered."
|
64
|
-
exit 1
|
65
|
-
end
|
66
|
-
else
|
67
|
-
# get results for a given day
|
68
|
-
day = match[3].to_i
|
69
|
-
|
70
|
-
begin
|
71
|
-
results = PlayWhe::Storage::Result.all_by_day(year, month, day).reverse
|
72
|
-
rescue
|
73
|
-
puts "Sorry, we encountered an error. Please check the date you entered."
|
74
|
-
exit 1
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
output = results.map do |result|
|
79
|
-
"Draw : #{result.draw}\nDate : #{result.date}\nPeriod: #{result.period}\nMark : #{result.mark} (#{PlayWhe::SPIRITS[result.mark]})"
|
80
|
-
end.join "\n\n"
|
81
|
-
puts output
|
82
|
-
end
|
92
|
+
PlayWhe.get.most_recent(limit: 4, order: options.fetch(:order, :desc))
|
83
93
|
end
|
84
|
-
rescue Interrupt
|
85
|
-
puts "Patience is a virtue. Sorry to see you didn't have any :). Bye!"
|
86
|
-
rescue
|
87
|
-
puts "Sorry, we encountered an error during processing."
|
88
94
|
end
|
95
|
+
|
96
|
+
def main(args, options)
|
97
|
+
good_results, bad_results = get_results(args, options)
|
98
|
+
puts as_csv(good_results) if good_results.any?
|
99
|
+
rescue PlayWhe::Error => e
|
100
|
+
STDERR.puts "Sorry, we were unable to retrieve the results"
|
101
|
+
STDERR.puts "Error: #{e.message}"
|
102
|
+
exit 1
|
103
|
+
rescue ArgumentError => e
|
104
|
+
STDERR.puts "Please check your options/arguments"
|
105
|
+
STDERR.puts "Error: #{e.message}"
|
106
|
+
exit 1
|
107
|
+
rescue => e
|
108
|
+
STDERR.puts "Sorry, we encountered an unknown error"
|
109
|
+
STDERR.puts "Error: #{e.message}"
|
110
|
+
exit 1
|
111
|
+
end
|
112
|
+
|
113
|
+
main(ARGV, options)
|