
import pandas as pd
import os
import datetime as dt
import json
import csv
from pathlib import Path
from datetime import date
from datetime import timedelta

import shutil
import metadata_parsing_functions
import numpy as np



def download_data(mode, version, n_max_tries, max_time_per_dl, start, stop, dl_root):
    # see download script EEA_AQ_eReporting
    # from October 2024 the API will have option to choose desired time period; until then, we will use https://discomap.eea.europa.eu/map/fme/AirQualityUTDExport.htm for nrt
    pass
      		


def download_metadata(n_max_tries, max_time_per_dl, version, dl_root, meta_basefile, meta_history, meta_params):
    # use metadata 1.5 and convert to json for 1.6. No download
    
    today = date.today()

    # read old file
    metadata = np.load('{}/EEA_AIRBASE/metadata/1.5/processed/EEA_AIRBASE_META.npy'.format(dl_root), allow_pickle=True)
    pandas_meta = pd.DataFrame(metadata)
    pandas_meta.to_csv('{}/EEA_AIRBASE/metadata/1.6/network_provided/EEA_AIRBASE_META_{}.csv'.format(dl_root, today.strftime('%Y%m%d')), index=False)


    # JSON =====================================================================
    network = os.path.basename(__file__).split('_downloa')[0]
    present_meta_file_id = today.strftime('%Y%m%d')

    metadata_parsing_functions.json_parser(dl_root, network, version, meta_basefile, meta_history, meta_params, present_meta_file_id)
