This Python script calculates basic statistics pulled from my haircut page.
Based on the original Gist created by Kyle Fox.
Number of haircuts recorded: 140 (Since October 10, 1998)
Shortest time between haircuts: 9 days (July 21, 2016 to July 30, 2016)
Longest time between haircuts: 138 days (November 28, 2022 to April 15, 2023)
Median time between haircuts: 69.0 days
Average time between haircuts: 68.8 days
Average time between last six haircuts: 50.8 days
Your last haircut was 2 days ago. (December 17, 2024)
You probably should get another haircut in about 48 days. (February 05, 2025)
- Ported script to Python 3
- Replaced
urllib2
library withurllib.request
library - Removed exception handling for malformed dates
- Median and average times are now formatted with a single decimal place
- Moved the script for Python 2 to the
/legacy/
directory
- Added calculation of the average time between the previous six haircuts
- The next haircut date is now based on the previous six haircut average
- Changed terminology from “period” to “time” in the output
- 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 time 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 occurring 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