import re def chunk_array(array, chunk_number) -> list: if len(array) <= chunk_number: return [array] out, tmp, index = [], [], 0 for el in array: tmp.append(el) index += 1 if index == chunk_number: out.append(tmp) tmp = [] index = 0 out.append(tmp) return out def parse_attachments(attachments) -> tuple: out = [] for attach in attachments: t = attach['type'] if t == 'wall': out.append(f'{t}{attach[t]["from_id"]}_{attach[t]["id"]}') else: out.append(f'{t}{attach[t]["owner_id"]}_{attach[t]["id"]}') return tuple(out) def parse_mention(mention: (str, None)) -> int: if not mention: return 0 reg = r'\[id(\d+)\|.+\]' match = re.match(reg, mention) if not match: return 0 return int(match.group(1)) async def get_user_sex(user_id, api): query = await api.users.get(user_ids=user_id, fields='sex') return query[0]['sex'] if len(query) > 0 else 2