Smith Python Madness. No more Guessing .pdf
Original filename: Smith - Python Madness. No more Guessing.pdf
Title: Python Madness: No more Guessing
Author: James R. Smith
This PDF 1.4 document has been generated by calibre 3.26.1 [https://calibre-ebook.com], and has been sent on pdf-archive.com on 11/01/2019 at 19:20, from IP address 46.219.x.x.
The current document download page has been viewed 30 times.
File size: 29.3 MB (280 pages).
Privacy: public file
Download original PDF file
Head to the Cloud
The Web Scrapers
Merging the Teams
The Big Show
A Closing Thank You
Introduction to Python Madness
Every year in March I go through the same ritual, on NCAA Selection Sunday
I watch all the talking heads and take notes, I then Spend the beginning of the
week creating a spreadsheet of all the bracket teams. I agonize over my choices;
don't get me wrong, it is also lots of fun to do. I then register my picks at the last
minute and then love watching the tournament.
I have always wanted a better/faster way to create my spreadsheet. I finally
decided to use my "mad skills" and create a more automated way. The first
decision was what programming language should I use? I picked Python because
It is A free and Open Source language, and is supported in both Windows and
Linux worlds. It is also a language that is very extensible by including modules
written by some very smart people.
Another goal for my project is I didn't want to spend lots of money on
software, I just wanted my spreadsheet to happen. Given this goal I created my
tools, and even wrote this book using all Open Source software.
My final goal is that with any programming project, you can over-think or
keep coding forever and never release the code. I’m sometimes guilty of this.
You can always improve things, so I have created a chapter in the book listing
several projects in my head that I wanted to do with my code. I figure that if I let
you guys do it, it will get done. The Projects Chapter is a way that you can add
your own "secret sauce" to your code to maybe give your spreadsheet an
advantage over everyone else?
Once you have bought my book the python code is yours, do what you wish
with it. Use it to become a better coder, use it to learn statistics, or just use it to
boost your "fun" during this cool time of year.
And when you guys win a big payout in your bracket/pool, smile and ... Keep
it all for yourself (grin)!
Finally, I suggest you carefully go though the Getting started chapter. Doing
this will ensure that you software is properly installed and running. When I was
coding the tools I needed to install some python extensions so I could
accomplish what I wanted to do. Pick either the Windows section or the Linux
section and run the test scripts against the code to make sure it is set up
Have fun and may your brackets never be broken during the Sweet Sixteen
Copyright © 2017 Jim Smith
All rights Reserved
Independently Published in the USA
I dedicate my first book to my wife and best friend, the one who puts
up with me and actually laughs at my jokes.
And to my daughter, I cannot be prouder of her. I love being Dad... Or
more often "Oh! Dad!”
Chapter 1 – for Windows - 1
Chapter 2 – for Linux - 37
Chapter 3 – Head to the Cloud... - 77
Chapter 4 – The Web Scrapers - 83
Chapter 5 – Merging the Teams – 109
Chapter 6– The Big Show – 121
Chapter 7– My Equipment – 137
Chapter 8– A Closing Thank You – 141
"I think it's wrong for a person to talk about themselves. A person's life
speaks for itself. If you've done good things people will spread the news, and
if you've done bad things people will spread the news too."
Note: Software was installed and tested using Windows 10 professional (build
Installing The Editor
In order to write software you will need an Editor. You could use windows
built in notepad or word-pad for this purpose, or perhaps use Microsoft Word,
but these editors are more suitable for writing a book than for a
developer/programmer; also, Word is expensive. The tools we will be installing
are freely Open Source and available on-line.
The editor I use is called VIM. This is a more advanced editor having a
learning curve, but because we want to dive in and more quickly get going, let's
How to install Notepad++ Get into your browser and go to this place:
https://notepad-plus-plus.org/. On the Left hand side of the page you should see
a cute lizard like critter. Under him is a "Download" menu option, click here. On
the right hand is now a
box labeled "Download 32-bit x86" click the green download button.
Go to your Download directory and double click the npp.7.5.1.Installer.exe
file (note: the version number could be different from 7.5.1, that is OK)
You will get a dialog box asking if it is OK to install this on your system; click
OK. You will then get a box asking what language to install. You will then
receive a Welcome box for Notepad++. Click on "Next". Now a license dialog
will appear; click "I Agree" as soon as you "Don't" read the License. Now it will
ask where you want the software to be installed, I suggest taking the Default,
here. There is a choose components screen, click the "Next" button.
Now there is a Choose which features to select (perhaps check the Create
Shortcut on desktop). Finally, click the "Install" button. Now Click "Finish"
Congratulations, you now have a proper programming editor installed.
Installing the Spreadsheet
(in our case we will get LibreOffice)
In order to plan and change your march madness picks a spreadsheet is
necessary. There are many to choose from: Google Docs is an on-line solution,
windows has Excel (once again, expensive). My pick is an open source tool also
used by many Linux Distros (including Ubuntu)
How to install LibreOffice; Pull up your browser and go to this page:
https://www.libreoffice.org/ At the top of the page is a "Download" button, Pick
the "Download LibreOffice" option. LibreOffice has a very current option and a
more stable option; let's do the more stable one. There is a Drop down where you
input your operating system (I picked windows x86_64).
go to the download directory and double click the
LibreOffice_5.3.7_Win_x64.msi file (note the 5.3.7 could be different, that is
You will get an install screen; click on the "Next" button. The next screen shows
a Typical or Custom option, I picked the Typical: once again press the "Next"
button. On the next Screen I checked the "Create a start link on the Desktop":
click the "Install" button. Finally click the "Finish" button.
All right! You now have a Spreadsheet installed.
The Source Control Tool
(we will use git)
If you wish to make changes to the python madness tools along with backing
up your changes to the cloud and allow getting back to an older version if you
want to, a source control tool is important. I use the open source option called
git. Later on in this book I will go over getting an on-line free account (github)
to allow the backing up of your changes.
How to install git: Get into your browser and go to this page: https://gitscm.com/ .
Press the "Download 2.15.0 for Windows" button in the Green computer
Go to the download directory and double click the file: Git-2.15.0-64-bit.exe
(Note: the version number of this file could be different; this is OK). The first
screen you will get during the install is the license screen (we always read it...
he-he), press the "Next" button.
You now get a screen where you want it to be installed; pick the Default and
Now you will see an options screen; press the "Next" button. On the next
screen press the "Next" button.
Now you will get an "Adjusting your path environment screen". The Default
option is fine, press "Next".
On the next screen I picked the "OpenSSL option"; pick "Next".
Oh, crap yet another screen, for the line endings pick the Default option and
And yet another window I would pick the "use Windows default console
window" option, and click "Next".
Yes, believe it or not, one more window take the default, and finally we get to
the "Install" button ... Whew ... Press it. OK, now press the finish button.
To show we have this tool installed go to the windows start menu and type
"CMD" and click on the "windows Command Prompt" icon.
Type the following into the window
or go to the start menu and type in "PowerShell"; click on the "windows
Type the following into the window:
Congratulations! You now have a source control tool installed!
The Programming Language (Python3)
The March Madness Tools are written in Python3, so we will install this now.
Get into your Browser and go to the following page: https://www.python.org/
Click on the blue "Download" button and pick the version 3 python for
windows. Currently it is version 3.6.3.
Go to download directory and double click the file: python-3.6.3.exe (in my
case it started running automatically).
Check the Box to add python to your path. Make sure to install the top option.
This is the option that has pip and the documentation. (click "Install Now").
You probably want to pick the "Disable path Length limit" option (press this
Press the "Close" button.
Congratulations! You now have Python3 and pip installed!
Let's make sure it is correctly running...
Go to the Windows Start Menu and search for "CMD", Click on the
"Command Prompt" option and an MSDOS window will appear.
(and make sure you see the python version)
(and make sure you see the pip version)
You can also test this using the Power Shell.
Go to the start menu and search for "Power Shell"; click on the windows
power shell app.
(and make sure you see the python version)
(and make sure you see the pip version)
Good! We are getting there!
Getting the Python Madness software
These are the cool March Madness Tools that are free with this book to make
your bracket picking much easier! Let's get these tools now. First, go to The
Windows Start Menu and open up a Power Shell App; it should default to your
Ok, now open your browser and go to this page:
https://github.com/meprogrammerguy/pyMadness This is my github location
storing the books python code.
Now press the green "Clone or Download" button; click on the "Copy to
Now go to the open Power Shell window on your box and type in this: git
clone https://github.com/meprogrammerguy/pyMadness.git (just type in the git
clone and a space and then right mouse and do a paste to get the saved clipboard
Press enter, and git will create a directory called "pyMadness" and save all of
the books tools to this directory.
you can type this:
and press enter, now type
and press enter
you should see the following
Cool! You now have the book tools on your system! Be aware that these tools
will not run until you install some additional python packages using pip. (This is
in the next section).
The Package Management System (pip)
If you installed Python you also installed pip. Pip is a tool provided by python
to add additional modules to extend the python standard language. The python
Madness tools will require a few of these additional modules, let's lay them
Installing Beautiful Soup
(BeautifulSoup4 - version for python3)
First of all, this is what you will see if you DO NOT install this optional
package when running scrape_stats.py or scrape_bracket.py.
Type in the following to install beautiful soup:
pip install BeautifulSoup4
you should see the following:
Installing package Pandas
If you DO NOT install Pandas you will see the following: