Welcome to the community!
My installation is somewhat fubared right now so I can’t test this, but I believe your answer lies in this documentation:
In your platformio.ini file use the following:
[env:pre_and_post_hooks]
extra_scripts = post:extra_script.py
extra_script.py should be in the same directory as your platformio.ini file.