See Cricket Match Score Without Opening a Website As a Notification on Mac/Linux/Windows


Well, this one is not exactly a tutorial on Linux. But it will definitely be a great experience reading this πŸ˜‰ In this post, I will demonstrate how we can use a Python script to see Live Cricket scores as notification alerts right on out laptops/desktops. Without opening a browser πŸ™‚ And all this along-with some learning about Linux/Mac. Sounds interesting? Read on πŸ˜‰

All this has been done on a Mac but same can be done on a Linux/Windows machine.

Install Python 3. Go to official site & download the stable version for your OS.

Download pip tool

bash-3.2# curl -O https://raw.github.com/pypa/pip/master/contrib/get-pip.py
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:--  0:00:03 --:--:--     0

Now execute this Python script.

bash-3.2# python3.4 get-pip.py

Now try installing a Python package called Beautiful Soup.

bash-3.2# pip3 install beautifulsoup4
Collecting beautifulsoup4
  Downloading beautifulsoup4-4.4.1-py3-none-any.whl (81kB)
    100% |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 81kB 2.2MB/s 
Installing collected packages: beautifulsoup4
Successfully installed beautifulsoup4-4.4.1
You are using pip version 7.1.2, however version 8.0.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

If you face similar issue, then upgrade your pip using below command.

bash-3.2# pip3 install --upgrade pip
Collecting pip
  Downloading pip-8.0.0-py2.py3-none-any.whl (1.2MB)
    100% |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 1.2MB 433kB/s 
Installing collected packages: pip
  Found existing installation: pip 7.1.2
    Uninstalling pip-7.1.2:
      Successfully uninstalled pip-7.1.2
Successfully installed pip-8.0.0

Now install below mentioned Python packages. These may or may not be already installed.

  • pync
  • python-dateutil
  • requests
  • six
bash-3.2# pip3 install pync
Collecting pync
  Downloading pync-1.6.1.tar.gz (363kB)
    100% |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 364kB 463kB/s 
Collecting python-dateutil>=2.0 (from pync)
  Downloading python_dateutil-2.4.2-py2.py3-none-any.whl (188kB)
    100% |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 192kB 1.3MB/s 
Collecting six>=1.5 (from python-dateutil>=2.0->pync)
  Downloading six-1.10.0-py2.py3-none-any.whl
Installing collected packages: six, python-dateutil, pync
  Running setup.py install for pync ... done
Successfully installed pync-1.6.1 python-dateutil-2.4.2 six-1.10.0
bash-3.2# pip3 install python-dateutil
Requirement already satisfied (use --upgrade to upgrade): python-dateutil in /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages
Requirement already satisfied (use --upgrade to upgrade): six>=1.5 in /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages (from python-dateutil)
bash-3.2# pip3 install requests
Collecting requests
  Downloading requests-2.9.1-py2.py3-none-any.whl (501kB)
    100% |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 503kB 21kB/s 
Installing collected packages: requests
Successfully installed requests-2.9.1
bash-3.2# pip3 install six
Requirement already satisfied (use --upgrade to upgrade): six in /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages

Thats it. All Python packages have been installed. Now install one more component terminal-notifier. Homebrew is a package manager for Mac. Please install it first to install other Mac stuff (like terminal-notifier) not bundled with its OS.

Shashank-MacBook-Pro:~ admin$ brew install terminal-notifier
==> Downloading https://homebrew.bintray.com/bottles/terminal-notifier-1.6.3.el_
######################################################################## 100.0%
==> Pouring terminal-notifier-1.6.3.el_capitan.bottle.tar.gz
==> Caveats
.app bundles were installed.
Run `brew linkapps terminal-notifier` to symlink these to /Applications.
==> Summary
🍺  /usr/local/Cellar/terminal-notifier/1.6.3: 12 files, 2.1M

Download score-notify Python script. Lets now download the actual Python script that will do the trick. Go to this siteΒ https://github.com/avinassh/score-notifyΒ & download this. All credit goes to this developer. His script does all the magic & he deserves all the accolades πŸ™‚ I am just using his work to demonstrate.

Once downloaded, just run it using Python.

bash-3.2# python3.4 cric-score-notify.py -f 30
/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/bs4/__init__.py:166: UserWarning: No parser was explicitly specified, so I'm using the best available HTML parser for this system ("html.parser"). This usually isn't a problem, but if you run this code on another system, or in a different virtual environment, it may use a different parser and behave differently.

To get rid of this warning, change this:

 BeautifulSoup([your markup])

to this:

 BeautifulSoup([your markup], "html.parser")

  markup_type=markup_type))

Following live scores are available now:

1 Afghanistan A 484/8  v Zimbabwe A 139/1 *
2 East Zone (Bangladesh) 203/8 * v North Zone (Bangladesh)
3 South Zone (Bangladesh) v Central Zone (Bangladesh) 233/5 *
4 Australia 348/8  v India 245/1 *
5 Colts Cricket Club 163/9  v Badureliya Sports Club 147/8 *
6 Sri Lanka Ports Authority Cricket Club 150/8  v Sri Lanka Army 153/4 *
7 Moors Sports Club 111/10 * v Saracens Sports Club 180/6 
8 England Lions 6 * v Pakistan A 192/10 
9 Bangladesh v Zimbabwe 72/1 *
10 Chilaw Marians Cricket Club 188/6 * v Tamil Union Cricket and Athletic Club
11 Bloomfield Cricket and Athletic Club v Galle Cricket Club 126/4 *
12 Nondescripts Cricket Club 129/5 * v Sinhalese Sports Club
13 Baroda v Uttar Pradesh
14 Trinidad & Tobago v Guyana


Enter your choice: 4


Great! I will keep displaying the scores now for every 30 seconds. And proxy set is to False.

This will show notifications about scores every 30 seconds πŸ™‚

Blog