如何让python 代码当天只运行一次

想设置电脑自启动打上班卡。怎么让代码当天只能运行一次呢?即不重复打上班卡。
谢谢。


import datetime
import os

today = datetime.date.today()
log_file = 'log.txt'

if os.path.exists(log_file):
    with open(log_file, 'r') as f:
        last_date_str = f.read().strip()
        last_date = datetime.datetime.strptime(last_date_str, '%Y-%m-%d').date()
        if last_date == today:
            print('今天已经打过卡了')
            exit()

with open(log_file, 'w') as f:
    f.write(str(today))
    
# 打卡代码

像这种的,可以在本站上直接搜索,就会有答案的