Flag emoji for Python.
Converts flag emoji to ASCII and other way round.
This is based on http://schinckel.net/2015/10/29/unicode-flags-in-python/ by schinckel
All the flag emoji are actually composed of two unicode letters. These are the 26 regional indicator symbols.
Alone they look like this:
๐ฆ ๐ง ๐จ ๐ฉ ๐ช ๐ซ ๐ฌ ๐ญ ๐ฎ ๐ฏ ๐ฐ ๐ฑ ๐ฒ ๐ณ ๐ด ๐ต ๐ถ ๐ท ๐ธ ๐น ๐บ ๐ป ๐ผ ๐ฝ ๐พ ๐ฟ
If you pair them up according to ISO 3166 some browsers and phones will display a flag.
For example TW is Taiwan: ๐น + ๐ผ = ๐น๐ผ
So, to encode an ASCII code like :TW:
to ๐น๐ผ, we just need to convert the ASCII T and W to the corresponding regional indicator symbols ๐น and ๐ผ.
To reverse it, we translate the regional indicator symbols back to ASCII letters.
>>> import flag
>>> flag.flag("IL")
'๐ฎ๐ฑ'
>>> flag.flag("GBENG")
'๐ด๓ ง๓ ข๓ ฅ๓ ฎ๓ ง๓ ฟ'
>>> flag.flagize("Flag of Israel :IL:")
'Flag of Israel ๐ฎ๐ฑ'
>>> flag.dflagize("Flag of Israel ๐ฎ๐ฑ")
'Flag of Israel :IL:'
>>> flag.flagize("England :gb-eng: is part of the UK :GB:", subregions=True)
'England ๐ด๓ ง๓ ข๓ ฅ๓ ฎ๓ ง๓ ฟ is part of the UK ๐ฌ๐ง'
>>> flag.dflagize("England ๐ด๓ ง๓ ข๓ ฅ๓ ฎ๓ ง๓ ฟ is part of the UK ๐ฌ๐ง", subregions=True)
'England :gb-eng: is part of the UK :GB:'
pip install emoji-country-flag
See: https://pypi.org/project/emoji-country-flag/
Python 3.7 or higher is required for the latest release. The last release for Python 2.7, 3.4 and 3.5 was v1.2.4.
Documentation at https://flag.readthedocs.io