






from typing import Dict, List, Optional, Union

import numpy as np

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import (
    center_crop,
    convert_to_rgb,
    get_resize_output_image_size,
    normalize,
    rescale,
    resize,
    to_channel_dimension_format,
)
from ...image_utils import (
    OPENAI_CLIP_MEAN,
    OPENAI_CLIP_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_vision_available, logging


A_	:	Union[str, Any]				=				logging.get_logger(__name__)


if is_vision_available():
   import PIL




class        _lowerCAmelCase( UpperCAmelCase_      ):





       """simple docstring"""







       a       :	List[str]								=['''pixel_values''']





       def __init__(      self						,    _lowerCamelCase = True						,    _lowerCamelCase = None						,    _lowerCamelCase = PILImageResampling.BICUBIC						,    _lowerCamelCase = True						,    _lowerCamelCase = None						,    _lowerCamelCase = True						,    _lowerCamelCase = 1 / 2_5_5						,    _lowerCamelCase = True						,    _lowerCamelCase = None						,    _lowerCamelCase = None						,    _lowerCamelCase = True						,    **_lowerCamelCase						,    ):
         super().__init__(**_lowerCamelCase							)
         UpperCamelCase_:      str					   =       size if size is not None else {'shortest_edge': 2_2_4}
         UpperCamelCase_:      int					   =       get_size_dict(_lowerCamelCase						,    default_to_square=_lowerCamelCase							)
         UpperCamelCase_:      str					   =       crop_size if crop_size is not None else {'height': 2_2_4, 'width': 2_2_4}
         UpperCamelCase_:      str					   =       get_size_dict(_lowerCamelCase							)

         UpperCamelCase_:      List[str]					   =       do_resize
         UpperCamelCase_:      Any					   =       size
         UpperCamelCase_:      str					   =       resample
         UpperCamelCase_:      str					   =       do_center_crop
         UpperCamelCase_:      Dict					   =       crop_size
         UpperCamelCase_:      Dict					   =       do_rescale
         UpperCamelCase_:      Dict					   =       rescale_factor
         UpperCamelCase_:      List[Any]					   =       do_normalize
         UpperCamelCase_:      Tuple					   =       image_mean if image_mean is not None else OPENAI_CLIP_MEAN
         UpperCamelCase_:      Optional[Any]					   =       image_std if image_std is not None else OPENAI_CLIP_STD
         UpperCamelCase_:      List[Any]					   =       do_convert_rgb





       def     _a					(      self						,    _lowerCamelCase						,    _lowerCamelCase						,    _lowerCamelCase = PILImageResampling.BICUBIC						,    _lowerCamelCase = None						,    **_lowerCamelCase						,    ):
         UpperCamelCase_:      Optional[int]					   =       get_size_dict(_lowerCamelCase						,    default_to_square=_lowerCamelCase							)
         UpperCamelCase_:      Any					   =       get_resize_output_image_size(
             _lowerCamelCase						,    size=(size['height'], size['width'])						,    default_to_square=_lowerCamelCase							)
         return resize(_lowerCamelCase						,    size=_lowerCamelCase						,    resample=_lowerCamelCase						,    data_format=_lowerCamelCase						,    **_lowerCamelCase							)





       def     _a					(      self						,    _lowerCamelCase						,    _lowerCamelCase						,    _lowerCamelCase = None						,    **_lowerCamelCase						,    ):
         UpperCamelCase_:      str					   =       get_size_dict(_lowerCamelCase							)
         return center_crop(_lowerCamelCase						,    size=(size['height'], size['width'])						,    data_format=_lowerCamelCase						,    **_lowerCamelCase							)





       def     _a					(      self						,    _lowerCamelCase						,    _lowerCamelCase						,    _lowerCamelCase = None						,    **_lowerCamelCase						,    ):
         return rescale(_lowerCamelCase						,    scale=_lowerCamelCase						,    data_format=_lowerCamelCase						,    **_lowerCamelCase							)





       def     _a					(      self						,    _lowerCamelCase						,    _lowerCamelCase						,    _lowerCamelCase						,    _lowerCamelCase = None						,    **_lowerCamelCase						,    ):
         return normalize(_lowerCamelCase						,    mean=_lowerCamelCase						,    std=_lowerCamelCase						,    data_format=_lowerCamelCase						,    **_lowerCamelCase							)





       def     _a					(      self						,    _lowerCamelCase						,    _lowerCamelCase = None						,    _lowerCamelCase = None						,    _lowerCamelCase = None						,    _lowerCamelCase = None						,    _lowerCamelCase = None						,    _lowerCamelCase = None						,    _lowerCamelCase = None						,    _lowerCamelCase = None						,    _lowerCamelCase = None						,    _lowerCamelCase = None						,    _lowerCamelCase = None						,    _lowerCamelCase = None						,    _lowerCamelCase = ChannelDimension.FIRST						,    **_lowerCamelCase						,    ):
         UpperCamelCase_:      str					   =       do_resize if do_resize is not None else self.do_resize
         UpperCamelCase_:      Optional[int]					   =       size if size is not None else self.size
         UpperCamelCase_:      Optional[int]					   =       get_size_dict(_lowerCamelCase						,    default_to_square=_lowerCamelCase							)
         UpperCamelCase_:      Union[str, Any]					   =       resample if resample is not None else self.resample
         UpperCamelCase_:      Optional[int]					   =       do_center_crop if do_center_crop is not None else self.do_center_crop
         UpperCamelCase_:      Union[str, Any]					   =       crop_size if crop_size is not None else self.crop_size
         UpperCamelCase_:      Tuple					   =       get_size_dict(_lowerCamelCase							)
         UpperCamelCase_:      Dict					   =       do_rescale if do_rescale is not None else self.do_rescale
         UpperCamelCase_:      Optional[int]					   =       rescale_factor if rescale_factor is not None else self.rescale_factor
         UpperCamelCase_:      Optional[Any]					   =       do_normalize if do_normalize is not None else self.do_normalize
         UpperCamelCase_:      List[Any]					   =       image_mean if image_mean is not None else self.image_mean
         UpperCamelCase_:      List[str]					   =       image_std if image_std is not None else self.image_std
         UpperCamelCase_:      str					   =       do_convert_rgb if do_convert_rgb is not None else self.do_convert_rgb

         UpperCamelCase_:      Union[str, Any]					   =       make_list_of_images(_lowerCamelCase							)

         if not valid_images(_lowerCamelCase							):
           raise ValueError(
               'Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, '
               'torch.Tensor, tf.Tensor or jax.ndarray.'							)

         if do_resize and size is None:
           raise ValueError('Size must be specified if do_resize is True.'							)

         if do_center_crop and crop_size is None:
           raise ValueError('Crop size must be specified if do_center_crop is True.'							)

         if do_rescale and rescale_factor is None:
           raise ValueError('Rescale factor must be specified if do_rescale is True.'							)

         if do_normalize and (image_mean is None or image_std is None):
           raise ValueError('Image mean and std must be specified if do_normalize is True.'							)

         # PIL RGBA images are converted to RGB
         if do_convert_rgb:
           UpperCamelCase_:      Optional[Any]					   =       [convert_to_rgb(_lowerCamelCase							) for image in images]

         # All transformations expect numpy arrays.
         UpperCamelCase_:      Optional[Any]					   =       [to_numpy_array(_lowerCamelCase							) for image in images]

         if do_resize:
           UpperCamelCase_:      Optional[Any]					   =       [self.resize(image=_lowerCamelCase						,    size=_lowerCamelCase						,    resample=_lowerCamelCase							) for image in images]

         if do_center_crop:
           UpperCamelCase_:      Optional[Any]					   =       [self.center_crop(image=_lowerCamelCase						,    size=_lowerCamelCase							) for image in images]

         if do_rescale:
           UpperCamelCase_:      Optional[int]					   =       [self.rescale(image=_lowerCamelCase						,    scale=_lowerCamelCase							) for image in images]

         if do_normalize:
           UpperCamelCase_:      Optional[Any]					   =       [self.normalize(image=_lowerCamelCase						,    mean=_lowerCamelCase						,    std=_lowerCamelCase							) for image in images]

         UpperCamelCase_:      Optional[Any]					   =       [to_channel_dimension_format(_lowerCamelCase						,    _lowerCamelCase							) for image in images]

         UpperCamelCase_:      str					   =       {'pixel_values': images}
         return BatchFeature(data=_lowerCamelCase						,    tensor_type=_lowerCamelCase							)







from datetime import date

import requests

A_	:	Any				=				'https://api.carbonintensity.org.uk/intensity'

def 						snake_case      () ->       str:
  UpperCamelCase_:      Any					   =       requests.get(UpperCAmelCase__						).json()['data'][0]
  return last_half_hour["intensity"]["actual"]

def 						snake_case      (UpperCAmelCase__			,					UpperCAmelCase__						) ->       list:
  return requests.get(F'''{BASE_URL}/{start}/{end}'''						).json()["data"]


if __name__ == "__main__":
   for entry in fetch_from_to(start=date(2020, 10, 1), end=date(2020, 10, 3)):
      print('from {from} to {to}: {intensity[actual]}'.format(**entry))
   print(F'''{fetch_last_half_hour() = }''')