Hello Gavin,
Would you mind sharing your code to automate the attendance?
I am new to Moodle and I have a project to create attendance automatically for specific courses so instructors do not need to add the sessions. I believe it is close to what you've accomplished here.
Thanks,
Juliana