import cdsapi

c = cdsapi.Client()

for format_file in ['grib','netcdf']:
    if format_file == 'grib':
        extension = '.grib'
    else:
        extension = '.nc'
    
    filename = '../archives/reanalysis/40_reanalysis-era5-land-monthly_means' + extension

    c.retrieve(
        'reanalysis-era5-land-monthly-means',
        {
            'format':format_file,
            'variable':'2m_temperature',
            'product_type':'monthly_averaged_reanalysis_by_hour_of_day',
            'year':'2005',
            'month':'01',
            'time':[
                '00:00','12:00'
            ]
        },
        filename)