import settings
from module.data_mode.data_metaclass import DataBaseModel
from PIL import Image
from io import BytesIO


class DataModeAutoDealPics(DataBaseModel):
    def __init__(self):
        super().__init__()

    def check_is_right_foot_by_api(self, image):
        image = image.convert('RGB')

        re_x = int(640)
        re_y = int(image.height * re_x / image.width)
        image = image.resize((re_x, re_y))
        e = "JPEG"

        img = BytesIO()
        image.save(img, format=e)  # format: PNG or JPEG
        img.seek(0)  # rewind to the start

        image_url = self.get_online_data.upload_image_by_io(image_io=img)
        if settings.IS_TEST:
            print("识别左右脚，{}".format(image_url))
        # 识别左右脚
        r_data = self.get_online_data.yolo_shoes_category(image_url=image_url)
        return r_data
