#!/usr/bin/env python
#
# Data Quality Checker also known as DQC
#
# Read the README.md for more detailed information
#
#       Barcelona Supercomputing Center - Centro Nacional de Supercomputacion
#       Earth Sciences Department - Computational Earth Sciences
#
#     Authors:
#       Joan Sala Calero (joan.sala@bsc.es)

import glob
from dqc_wrapper.utils.utils_db import *

# Create connection to SQLITE file
current_dir = os.path.dirname(os.path.realpath(__file__))
conn = create_connection(os.path.join(current_dir, './dqc_workflow.db'))

# Get all grib files
dataset = 'reanalysis-era5-single-levels-monthly-means-2m_temperature'
files = glob.glob('/shared/cds_downloads/reanalysis/reanalysis-era5-single-levels-monthly-means/2m_temperature/*.grib')
update_filedatetimes(conn, dataset, files)
print('Updated: {}'.format(dataset))

dataset = 'seasonal-monthly-single-levels-2m_temperature-ecmwf-5'
files = glob.glob('/shared/cds_downloads/seasonal/seasonal-monthly-single-levels/2m_temperature/ecmwf-5*.grib')
update_filedatetimes(conn, dataset, files)
print('Updated: {}'.format(dataset))

dataset = 'reanalysis-era5-single-levels-2m_temperature'
files = glob.glob('/shared/cds_downloads/reanalysis/reanalysis-era5-single-levels/2m_temperature/*.grib')
update_filedatetimes(conn, dataset, files)
print('Updated: {}'.format(dataset))

dataset = 'seasonal-original-single-levels-2m_temperature-meteo_france-7'
files = glob.glob('/shared/cds_downloads/seasonal/seasonal-original-single-levels/2m_temperature/meteo_france-7*.grib')
update_filedatetimes(conn, dataset, files)
print('Updated: {}'.format(dataset))