<commit_before>from copy import deepcopy as copy

from button import ButtonTemplate
ButtonTemplate.get_buttons = lambda self: self.template['attachment']['payload']['buttons']

TITLE_CHARACTER_LIMIT = 80
SUBTITLE_CHARACTER_LIMIT = 80
BUTTON_TITLE_CHARACTER_LIMIT = 20
BUTTON_LIMIT = 3
ELEMENTS_LIMIT = 10

template = {
    'template_type': 'generic',
    'value': {
        'attachment': {
            'type': 'template',
            'payload': {
                'template_type': 'generic',
                'elements': []
            }
        }
    }
}

class GenericTemplate:
    def __init__(self):
        self.template = copy(template['value'])
        self.elements = []
    def add_element(self, title='', item_url='', image_url='', subtitle='', buttons=[]):
        element = {}
        element['title'] = title[:TITLE_CHARACTER_LIMIT]
        if item_url != '':
            element['item_url'] = item_url
        element['image_url'] = image_url
        if subtitle != '':
            element['subtitle'] = subtitle[:SUBTITLE_CHARACTER_LIMIT]
        for button in buttons:
            button['title'] = button['title'][:BUTTON_TITLE_CHARACTER_LIMIT]
        if len(buttons) > 0:
            element['buttons'] = buttons[:BUTTON_LIMIT]
        if len(self.elements) < ELEMENTS_LIMIT:
            self.elements.append(element)
    def get_message(self):
        self.template['attachment']['payload']['elements'] = self.elements
        return self.template
<commit_msg>Add support for images with square aspect ratio in GenericTemplate<commit_after>from copy import deepcopy as copy

from button import ButtonTemplate
ButtonTemplate.get_buttons = lambda self: self.template['attachment']['payload']['buttons']

TITLE_CHARACTER_LIMIT = 80
SUBTITLE_CHARACTER_LIMIT = 80
BUTTON_TITLE_CHARACTER_LIMIT = 20
BUTTON_LIMIT = 3
ELEMENTS_LIMIT = 10

template = {
    'template_type': 'generic',
    'value': {
        'attachment': {
            'type': 'template',
            'payload': {
                'template_type': 'generic',
                'image_aspect_ratio': 'horizontal',
                'elements': []
            }
        }
    }
}

class GenericTemplate:
    def __init__(self):
        self.template = copy(template['value'])
        self.elements = []
    def set_image_aspect_ratio_to_square(self):
        self.template['attachment']['payload']['image_aspect_ratio'] = 'square'
    def add_element(self, title='', item_url='', image_url='', subtitle='', buttons=[]):
        element = {}
        element['title'] = title[:TITLE_CHARACTER_LIMIT]
        if item_url != '':
            element['item_url'] = item_url
        element['image_url'] = image_url
        if subtitle != '':
            element['subtitle'] = subtitle[:SUBTITLE_CHARACTER_LIMIT]
        for button in buttons:
            button['title'] = button['title'][:BUTTON_TITLE_CHARACTER_LIMIT]
        if len(buttons) > 0:
            element['buttons'] = buttons[:BUTTON_LIMIT]
        if len(self.elements) < ELEMENTS_LIMIT:
            self.elements.append(element)
    def get_message(self):
        self.template['attachment']['payload']['elements'] = self.elements
        return self.template

{'fraction_non_alphanumeric': 0.13076199435559738, 'fraction_numerical': 0.006271558482282847, 'mean_word_length': 2.8157894736842106, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6471319', 'n_tokens_mistral': 942, 'n_tokens_neox': 934, 'n_words': 181}