auto_print_infomail.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/usr/bin/env python3
  2. # Copyright © 2023 Noah Vogt <noah@noahvogt.com>
  3. # This program is free software: you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation, either version 3 of the License, or
  6. # (at your option) any later version.
  7. # This program is distributed in the hope that it will be useful,
  8. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. # GNU General Public License for more details.
  11. # You should have received a copy of the GNU General Public License
  12. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. from os import system
  14. from datetime import datetime
  15. from re import match
  16. import colorama
  17. from utils import make_sure_file_exists, get_current_yyyy_mm_dd_date
  18. from input import validate_autoprint_infomail_config, get_cachefile_content
  19. import config as const
  20. def is_sunday() -> bool:
  21. today = datetime.today()
  22. return today.weekday() == 6
  23. def already_printed_today() -> bool:
  24. cachefile_content = get_cachefile_content(const.AUTOPRINT_INFOMAIL_DATEFILE)
  25. return bool(
  26. match(r"[0-9]{4}-[0-9]{2}-[0-9]{2}$", cachefile_content[0])
  27. and cachefile_content[0].strip() == get_current_yyyy_mm_dd_date()
  28. )
  29. if __name__ == "__main__":
  30. colorama.init()
  31. validate_autoprint_infomail_config()
  32. make_sure_file_exists(const.AUTOPRINT_INFOMAIL_DATEFILE, gui_error_out=True)
  33. if is_sunday() and not already_printed_today():
  34. system(const.AUTOPRINT_INFOMAIL_CMD)