import os
import time
from config import *


# 定期删除特定文件夹内特征的文件
def remove_files(fileDir):
    for eachFile in os.listdir(fileDir):
        condition_a = os.path.isfile(fileDir + "/" + eachFile)
        condition_b = ("DiaryTop3000.csv" in eachFile) or ("output.txt" in eachFile) or ("feed" in eachFile)
        if condition_a and condition_b:
            ft = os.stat(fileDir + "/" + eachFile)
            ltime = int(ft.st_mtime)
            # 删除5分钟前的文件
            ntime = int(time.time()) - 5*60
            if ltime <= ntime:
                os.remove(fileDir + "/" + eachFile)

def delete_log():
    for eachFile in os.listdir("/tmp"):
        if "xlearn" in eachFile:
            os.remove("/tmp" + "/" + eachFile)


if __name__ == "__main__":
    while True:
        delete_log()
        remove_files(DIRECTORY_PATH + "result")
        print("运行一次")
        time.sleep(5*60)
