(emojis_lines: list, sequences_lines: list)
return output
Extract emojis line by line to dict
Extract emojis line by line to dict
Extract emojis line by line to dict
def extract_emojis(emojis_lines: list, sequences_lines: list) -> dict:
    """Extract emojis line by line to dict"""

    output = {}
    for line in emojis_lines:
        if not line == "" and not line.startswith("#"):
            emoji_status = line.split(";")[1].strip().split(" ")[0]

            codes = line.split(";")[0].strip().split(" ")
            separated_line = line.split(" # ")[-1].strip().split(" ")
            separated_name = separated_line[2:]
            version_str = separated_line[1]
            emoji_name = (
                "_".join(separated_name)
                .removeprefix("flag:_")
                .replace(":", "")
                .replace(",", "")
                .replace("\u201c", "")
                .replace("\u201d", "")
                .replace("\u229b", "")
                .strip()
                .replace(" ", "_")
            )

            emoji_code = "".join(
                [
                    "\\U0000" + code if len(code) == 4 else "\\U000" + code
                    for code in codes
                ]
            )

            version = float(version_str.replace("E", "").strip())

            if emoji_code in output:
                raise Exception("Duplicate emoji: " +
                                emoji_name + " " + emoji_code)

            output[emoji_code] = {
                "en": emoji_name,
                "status": emoji_status.replace("-", "_"),
                "version": version
            }

    # Walk through the emoji-variation-sequences.txt
    for line in sequences_lines:
        if not line == "" and not line.startswith("#"):
            # No variant
            normal_codes = line.split(";")[0].strip().split(" ")
            normal_code = "".join(
                [
                    "\\U0000" + code if len(code) == 4 else "\\U000" + code
                    for code in normal_codes
                ]
            )
            n = 0
            if normal_code in output:
                output[normal_code]["variant"] = True

            # Text variant U+FE0E
            text_codes = re.sub(r'\s*FE0E\s*$', '',
                                line.split(";")[0]).strip().split(" ")
            text_code = "".join(
                [
                    "\\U0000" + code if len(code) == 4 else "\\U000" + code
                    for code in text_codes
                ]
            )
            if text_code in output:
                output[text_code]["variant"] = True

            # Emoji variant U+FE0F
            emoji_codes = re.sub(r'\s*FE0F\s*$', '', line.split(";")[0]).strip().split(" ")
            emoji_code = "".join(
                [
                    "\\U0000" + code if len(code) == 4 else "\\U000" + code
                    for code in emoji_codes
                ]
            )
            if emoji_code in output:
                output[emoji_code]["variant"] = True

    return output
def extract_emojis ( emojis_lines : list , sequences_lines : list ) -> dict : output = { } for line in emojis_lines : if not line == "" and not line . startswith ( "#" ) : emoji_status = line . split ( ";" ) [ 1 ] . strip ( ) . split ( " " ) [ 0 ] codes = line . split ( ";" ) [ 0 ] . strip ( ) . split ( " " ) separated_line = line . split ( " # " ) [ - 1 ] . strip ( ) . split ( " " ) separated_name = separated_line [ 2 : ] version_str = separated_line [ 1 ] emoji_name = ( "_" . join ( separated_name ) . removeprefix ( "flag:_" ) . replace ( ":" , "" ) . replace ( "," , "" ) . replace ( "\u201c" , "" ) . replace ( "\u201d" , "" ) . replace ( "\u229b" , "" ) . strip ( ) . replace ( " " , "_" ) ) emoji_code = "" . join ( [ "\\U0000" + code if len ( code ) == 4 else "\\U000" + code for code in codes ] ) version = float ( version_str . replace ( "E" , "" ) . strip ( ) ) if emoji_code in output : raise Exception ( "Duplicate emoji: " + emoji_name + " " + emoji_code ) output [ emoji_code ] = { "en" : emoji_name , "status" : emoji_status . replace ( "-" , "_" ) , "version" : version } # Walk through the emoji-variation-sequences.txt for line in sequences_lines : if not line == "" and not line . startswith ( "#" ) : # No variant normal_codes = line . split ( ";" ) [ 0 ] . strip ( ) . split ( " " ) normal_code = "" . join ( [ "\\U0000" + code if len ( code ) == 4 else "\\U000" + code for code in normal_codes ] ) n = 0 if normal_code in output : output [ normal_code ] [ "variant" ] = True # Text variant U+FE0E text_codes = re . sub ( r'\s*FE0E\s*$' , '' , line . split ( ";" ) [ 0 ] ) . strip ( ) . split ( " " ) text_code = "" . join ( [ "\\U0000" + code if len ( code ) == 4 else "\\U000" + code for code in text_codes ] ) if text_code in output : output [ text_code ] [ "variant" ] = True # Emoji variant U+FE0F emoji_codes = re . sub ( r'\s*FE0F\s*$' , '' , line . split ( ";" ) [ 0 ] ) . strip ( ) . split ( " " ) emoji_code = "" . join ( [ "\\U0000" + code if len ( code ) == 4 else "\\U000" + code for code in emoji_codes ] ) if emoji_code in output : output [ emoji_code ] [ "variant" ] = True return output