This Python script calculates basic statistics pulled from my haircut page.
Based on the original Gist created by Kyle Fox.
Number of haircuts recorded: 106 (Since October 10, 1998)
Shortest period between haircuts: 9 days (July 21, 2016 to July 30, 2016)
Longest period between haircuts: 120 days (August 11, 2007 to December 09, 2007)
Average period between haircuts: 74 days
Median period between haircuts: 73 days
Your last haircut was 82 days ago. (March 05, 2020)
You probably should’ve had a haircut 8 days ago. (May 18, 2020)
- Added fix for failed certificate verification related to the
urllib2.py
library
- Updated to Beautiful Soup 4
- Added
html.parser
argument toBeautifulSoup()
constructor
- Added “User-agent” header to fix
urllib2.HTTPError: HTTP Error 406: Not Acceptable
- Standardized variable naming and value quoting because consistency
- Added calculation of the median period between haircuts
- Modified output for even more consistent display of days and dates
- Added newlines before and after output because readability
- Modified output for haircuts occuring one day ago
- Modified output for consistent display of days and dates
- Added more descriptive “next haircut” strings
- Added logic to display “day zero” status
- Updated URLs to use https
- Added note regarding Beautiful Soup requirement
- Set UTF-8 encoding
- Educated the apostrophes
- Minor edits and formatting tweaks