A Script That Rebuilds the Report
A Script That Rebuilds the Report: Paths and Folders with pathlib, Command-Line Options with argparse, A Report Script That Finds the Newest Data, Writing the…
Updated
- Paths and Folders with pathlib (Apprentice): A Path from Python's pathlib module holds a file's or folder's address in parts, so a script can join paths with /, read a file's name and extension, list and find the files in a folder, and make folders, the same way on Windows and on a Mac.
- Command-Line Options with argparse (Journeyman): The words typed after a script's name arrive in sys.argv, and the argparse module turns them into a positional argument, options with defaults and flags, checks them, and writes a --help page, so one script works on any folder without editing its code.
- A Report Script That Finds the Newest Data (Journeyman): A report script runs with one command instead of a person running notebook cells, finds the newest week's file with sorted and glob (which works because the file names start with the year), stacks every week into one table with concat, and takes its folder as an option through a main(argv) function, so running it again next week builds next week's report.
- Writing the Report: Charts and Tables on a Web Page (Journeyman): A report someone else reads is a web page, so the script saves each chart as a PNG with savefig and closes it, turns tables into HTML with to_html, builds the page with an f-string, and writes it into a folder of its own for each week, ready to open in any browser.