Script check if all CSV files that i generated from data source is up to date.
Python
import os
import glob
import datetime
path = "/path/to/file/"
extension = 'csv'
os.chdir(path)
result = [i for i in glob.glob('**/*.{}'.format(extension), recursive=True)]
result.sort(key=os.path.getmtime, reverse=True)
for file in result:
file_date = datetime.datetime.fromtimestamp(os.path.getmtime(file))
if file_date.date() == datetime.datetime.today().date():
print(f"{file} - File is up to date", f"- {file_date}")
else:
print(f"{file} - file is too old !", f"- {file_date}")
Example :
Bash
python3 chk_date.py
scrape_jobs/jobs_test.csv - File is up to date - 2023-08-06 13:18:53.760668
scrape_jobs/job_offers_salary.csv - File is up to date - 2023-08-06 13:18:53.741668
scrape_jobs/job_offers.csv - File is up to date - 2023-08-06 13:18:52.993673