A Python library and CLI for the retrieval and storage of Play Whe results.
Project description
A Python library and CLI for the retrieval and storage of Play Whe results from the National Lotteries Control Board (NLCB).
I originally wrote playwhe
in 2011 when I wanted to work on a small
project to build a RESTful API for Play Whe. The project has grown since then
and this code continues to play a key role in it.
playwhe
helps many people access Play Whe results in a convenient way.
Installation
To install, simply use pip (or pipenv):
$ pip install playwhe
Usage
The library currently supports the implementation of the CLI. In the future, a developer would also be able to use the library within another application to query a database of Play Whe results in useful and interesting ways.
So what can the CLI do?
There are 3 main things you can do with playwhe
on the command-line:
Initialize a database for storing Play Whe results.
Load Play Whe results from a CSV file into the database.
Sync or update the database with the latest results from NLCB’s servers.
Initialize
To initialize a database for storing Play Whe results you need to run the following:
$ playwhe --init sqlite:////home/dwayne/playwhe.db
The command creates a new SQLite database in the playwhe.db
file in the
/home/dwayne
directory. The database contains the tables needed for
storing the Play Whe results.
Once the database has been initialized you can begin to load or sync the Play Whe results as needed.
Load
To load Play Whe results from a CSV file into the database you need to run the following:
$ playwhe --load results.csv sqlite:////home/dwayne/playwhe.db
results.csv
is a CSV file that contains the results you intend to load
into the database.
Each line in the CSV file needs to be in the format:
<draw:1,2,3,...>,<date:yyyy-mm-dd>,<period:EM|AM|AN|PM>,<number:1-36>
The load command is intended to be used, only once, when you’re starting off with an empty database, i.e. when you’ve just initialized the database. In fact, you can initialize and load the database in one command by running the following:
$ playwhe -il results.csv sqlite:////home/dwayne/playwhe.db
-i
is shorthand for --init
and -l
is shorthand for
--load
.
You can find a slightly out-of-date results.csv
file in the data
directory of this project. I update it occasionally so that you don’t have to do
too much syncing when you’re starting from an empty database.
Another benefit of using data/results.csv
is that if there’s any error
in the results provided by NLCB then I usually fix it in the CSV file. So at
least you know you’re starting off with good data.
Sync
To update the database with the latest results from NLCB’s servers you need to run the following:
$ playwhe --verbose --sync sqlite:////home/dwayne/playwhe.db
If you’re starting from an empty database or a really out-of-date database then be prepared to wait a while since the program has to fetch the data from a remote server.
The --verbose
option is not necessary but it’s helpful. Use it to keep
track of the task when you’re running it interactively.
If you intend to sync using a cron job then I’d recommend removing the
verbose
flag and also redirecting standard error to a log file. Here’s
what the command would look like:
$ playwhe --sync sqlite:////home/dwayne/playwhe.db 2>> /home/dwayne/playwhe.log
What else can the CLI do?
Not much else at the moment but you can always access help to get a refresher on how to perform a certain task:
$ playwhe --help
Development
Recommended tools:
Clone the repository and install the dependencies:
$ git clone git@github.com:playwhesmarter/playwhe.git
$ cd playwhe
$ pipenv shell
$ pipenv install --dev
You’re now all set to begin development.
Testing
Tests are written using the built-in unit testing framework, unittest.
Run all tests.
$ python -m unittest
Run a specific test module.
$ python -m unittest tests.playwhe.scraper.test_client
Run a specific test case.
$ python -m unittest tests.playwhe.scraper.test_client.FetchFromMockServerTestCase.test_when_it_succeeds
Resources
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for playwhe-0.8.0a1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 56a08689ce0dcb2fab274c3465e68d8899934e88c6ed71e38c61d73e30cd095c |
|
MD5 | 59da33452dcff7db57a79f7b161f5bcd |
|
BLAKE2b-256 | 89a56bf46f5f8f62ca33c1c31c2d2f17f400335b4c4089c164e229463ea34421 |