telegram_avatar/avatar_generator.py
def generate(self, avatar_name: str = "Avatar.png") -> os.path:
        """
        Method which generates avatar image with time and current weather data
        or only with current time if weather data is not available.
        Args:
            avatar_name: the name of the file with which the generated
                avatar will be saved.
        Returns:
            os.path object - absolute path to the generated avatar image.
        """
        # Create background
        bg = Image.new(
            mode="RGBA",
            size=(200, 200),
            color=self._bg_color + (255,),
        )
        canvas = ImageDraw.Draw(bg)
        # Get and format current time
        current_time = datetime.now()
        time = "{:0>2d}:{:0>2d}".format(current_time.hour, current_time.minute)
        self._logger.info(f"Creating new avatar with name {avatar_name}...")
        # If up-to-date weather data exists
        if self._weather_data.is_up_to_date():
            # Prepare weather icon
            icon_path = os.path.join(
                os.getcwd(),
                WEATHER_ICONS_FOLDER_NAME,
                self._weather_data.current_weather_image + ".png",
            )
            icon = Image.open(icon_path, "r")
            # Convert temperature
            temperature = self._get_celsius_from_kelvin(
                t_kelvin=self._weather_data.current_temperature,
            )
            # Draw icon on background
            bg.paste(im=icon, box=(50, 55), mask=icon)
            # Draw time in background
            canvas.text(
                xy=(35, 20),
                text=time,
                font=self._font_time,
                fill=self._text_color,
            )
            # Draw temperature on background
            canvas.text(
                xy=(65, 130),
                text=temperature,
                font=self._font_temperature,
                fill=self._text_color,
            )
        # If weather data is out of date
        else:
            # Draw just time on background with larger font
            canvas.text(
                xy=(20, 55),
                text=time,
                font=self._font_time_larger,
                fill=self._text_color,
            )
        # Saving new avatar
        bg.save(avatar_name)
        return os.path.abspath(avatar_name)

        Method which generates avatar image with time and current weather data
        or only with current time if weather data is not available.
        Args:
            avatar_name: the name of the file with which the generated
                avatar will be saved.
        Returns:
            os.path object - absolute path to the generated avatar image.
        
Method which generates avatar image with time and current weather data
or only with current time if weather data is not available.
Method which generates avatar image with time and current weather data or only with current time if weather data is not available .
def generate(self, avatar_name: str = "Avatar.png") -> os.path:
        bg = Image.new(
            mode="RGBA",
            size=(200, 200),
            color=self._bg_color + (255,),
        )
        canvas = ImageDraw.Draw(bg)
        current_time = datetime.now()
        time = "{:0>2d}:{:0>2d}".format(current_time.hour, current_time.minute)
        self._logger.info(f"Creating new avatar with name {avatar_name}...")
        if self._weather_data.is_up_to_date():
            icon_path = os.path.join(
                os.getcwd(),
                WEATHER_ICONS_FOLDER_NAME,
                self._weather_data.current_weather_image + ".png",
            )
            icon = Image.open(icon_path, "r")
            temperature = self._get_celsius_from_kelvin(
                t_kelvin=self._weather_data.current_temperature,
            )
            bg.paste(im=icon, box=(50, 55), mask=icon)
            canvas.text(
                xy=(35, 20),
                text=time,
                font=self._font_time,
                fill=self._text_color,
            )
            canvas.text(
                xy=(65, 130),
                text=temperature,
                font=self._font_temperature,
                fill=self._text_color,
            )
        else:
            canvas.text(
                xy=(20, 55),
                text=time,
                font=self._font_time_larger,
                fill=self._text_color,
            )
        bg.save(avatar_name)
        return os.path.abspath(avatar_name)
def generate ( self , avatar_name : str = "Avatar.png" ) -> os . path : bg = Image . new ( mode = "RGBA" , size = ( 200 , 200 ) , color = self . _bg_color + ( 255 , ) , ) canvas = ImageDraw . Draw ( bg ) current_time = datetime . now ( ) time = "{:0>2d}:{:0>2d}" . format ( current_time . hour , current_time . minute ) self . _logger . info ( f"Creating new avatar with name {avatar_name}..." ) if self . _weather_data . is_up_to_date ( ) : icon_path = os . path . join ( os . getcwd ( ) , WEATHER_ICONS_FOLDER_NAME , self . _weather_data . current_weather_image + ".png" , ) icon = Image . open ( icon_path , "r" ) temperature = self . _get_celsius_from_kelvin ( t_kelvin = self . _weather_data . current_temperature , ) bg . paste ( im = icon , box = ( 50 , 55 ) , mask = icon ) canvas . text ( xy = ( 35 , 20 ) , text = time , font = self . _font_time , fill = self . _text_color , ) canvas . text ( xy = ( 65 , 130 ) , text = temperature , font = self . _font_temperature , fill = self . _text_color , ) else : canvas . text ( xy = ( 20 , 55 ) , text = time , font = self . _font_time_larger , fill = self . _text_color , ) bg . save ( avatar_name ) return os . path . abspath ( avatar_name )
Method which generates avatar image with time and current weather data
or only with current time if weather data is not available.
Method which generates avatar image with time and current weather data or only with current time if weather data is not available .
"""
        Method which generates avatar image with time and current weather data
        or only with current time if weather data is not available.
        Args:
            avatar_name: the name of the file with which the generated
                avatar will be saved.
        Returns:
            os.path object - absolute path to the generated avatar image.
        """ # Create background # Get and format current time # If up-to-date weather data exists # Prepare weather icon # Convert temperature # Draw icon on background # Draw time in background # Draw temperature on background # If weather data is out of date # Draw just time on background with larger font # Saving new avatar
os.path object - absolute path to the generated avatar image.
os . path object - absolute path to the generated avatar image .
self
avatar_name
str
the name of the file with which the generated
avatar will be saved.
the name of the file with which the generated avatar will be saved .