This code is the server backend for streaming live basketball scores and stats. It is based on the IBM Bluemix service stack and PubNub BLOCKs microservice.
Following cloud services are used
IBM Cloudant DB
To test the application we have used two python scripts
gamesimulation.py : Game simulation script that simulates a 48 minute basketball game.
ScoreboardUI.py : Terminal UI script for viewing the live score. This works only on UNIX/LINUX based terminals. WINDOWS is not supported.
Clone this repository and follow the steps below to setup the services.
Cloudant DB creation.
Step 1 : Login to your Bluemix account with the valid credentials.
Step 2 : Goto Catalog and under "Data & Analytics" select "Cloudant NoSQL DB".
Step 3 : Give a name to the Service.
Step 4 : Scroll down in the same page and Select the Free plan and click on the Create button.
Step 5 : After you create the service open it and click on the "Service credentials" and then, click on the "New credentials" and save those credentials. Step 6 : After you got the new credentials, click on the "Manage" from the menu and select "LAUNCH" button.
Step 7 : Click on the "Create Database" and Give a name for the Database then click on the Create button.
OpenWhisk service creation
Step 1 : Login to your Bluemix account with valid credentials.
Step 2 : Goto catalog and under "Apps", select "OpenWhisk".
Step 3 : Click on the "Develop in your Browser".
Step 4 : Click on the "Create an Action" button to create new action.
Step 5 : Give a name to the action and select Nodejs Runtime. Select a blank slate to start with and then click on the "Create Action" button.
Step 6 : Copy the code and paste in the code area in the newly created action. Update the code to point to your Cloudant DB instance (Refer sub section Openwhisk Config) and then click on "Make it live" to update the action.
To Test the newly created openwhisk action.
To invoke this openwhisk action through a REST call.
PubNub BLOCK Creation
Refer Block Readme file for the steps to create the two BLOCKS that we have used in this application.
Application Credentials Setup
You need to make a note of the following credentials generated from the Cloudant, OpenWhisk and PubNub services .
Cloudant service credentials : Refer Step 5 Under the section "Cloudant DB creation" above.
OpenWhisk Authorization : Refer Step 11 under "Open whisk creation" for the generated Authorization and the url that you generated.
PubNub Publish and Subscribe Key : Refer Step 4 under Pubnub block creation
Before deploying, you need to add these credentials at specific places in the application code as guided below.
Simulation Code Configuration
Steps you should follow before running the game simulation and UI script.
Both the scripts depend on a few python libraries. You can install them using the pip utility.
Step 1 : pip install pubnub==3.8.3
Step 2 : pip install cloudant (https://github.com/cloudant/python-cloudant)
Game Simulation Script config
Before running the game simulation script make sure to update the code .
- Edit the following variable's values as per "Cloudant service credentials" in the game simulation code
USERNAME - line number 233
PASSWORD - line number 234
ACCOUNT_NAME - line number 235
- Edit the following variable's values as per "PubNub Publish and Subscribe Key"
pub_key - line number 239
sub_key - line number 240
Terminal UI Script config
Before running the UI scoreboard script make sure to update the code .
Edit the following variable's values as per "PubNub Publish and Subscribe Key" in the UI scoreboard code
pub_key - line number 252
sub_key - line number 253
Microservice Code Configuration
Steps you should follow to update the OpenWhisk and BLOCK code before launching these services.
Edit the following variable's values as per "Cloudant service credentials" in the OpenWhisk action code
url - line number 5
Edit the following variable's values as per "OpenWhisk Authorization" in the BLOCK code
auth - line number 10
url - line number 48