Last active
August 25, 2016 16:22
-
-
Save glasnt/b6ef7948fdcae8c200043ac8529778a9 to your computer and use it in GitHub Desktop.
๐ทโ๐ชโ๐ฌโ๐ฎโ๐ดโ๐ณโ๐ฆโ๐ฑโ โ๐ฎโ๐ณโ๐ฉโ๐ฎโ๐จโ๐ฆโ๐นโ๐ดโ๐ทโ โ๐จโ๐ญโ๐ฆโ๐ทโ๐ฆโ๐จโ๐นโ๐ชโ๐ทโ๐ธโ โ๐ฆโ๐ธโ โ๐ฆโ โ๐ธโ๐ชโ๐ทโ๐ปโ๐ฎโ๐จโ๐ช
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Usage: python3 regional.py list of words | |
Prints a representation of the words as Regional Identifiers, and copies the output directly to keyboard for you | |
This is because some terminals think that zero width spaces are silly. | |
Currently supports: A-Z | |
Requires: Python 3 | |
Now less complex, thanks @bmispelon! | |
""" | |
import sys | |
import xerox | |
import unicodedata | |
def regional_indicator(letter): | |
# Try and see if there's a REGIONAL INDICATOR SYMBOL for our letter. | |
try: | |
return unicodedata.lookup('REGIONAL INDICATOR SYMBOL LETTER %s' % letter.upper()); | |
except KeyError: | |
return letter | |
output = "\u200B".join([regional_indicator(x) for x in " ".join(sys.argv[1:]).upper()]) | |
xerox.copy(output) | |
print("Copied to Clipboard: %s" % output) |
@bmispelon Thank you! ๐ I thought there'd be a better way than what I had. I've updated it accordingly
You could even lookup 'REGIONAL INDICATOR SYMBOL LETTER A' and just add an offset from there (they are in sequence), instead of looking up each letter in the Unicode database.
A few more silly comments:
The list comprehension's brackets '[ ]' inside the join() can be removed to turn it into a generator expression, which is faster and does the same thing.
The code currently sandwiches Zero-Width Spaces between regional indicators and spaces between words, which isn't necessary. Can be fixed by joining with U+200B before joining with " ".
You can even one-line it if you're feeling particularly evil. Something like
`output = "\u200B".join([unicodedata.lookup('REGIONAL INDICATOR SYMBOL LETTER %s' % x.upper()) if 65 <= ord(x.upper()) <= 90 else ' ' for x in ' '.join(sys.argv[1:])])`
should work ๐
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use
unicodedata.lookup('REGIONAL INDICATOR SYMBOL LETTER %s' % letter.upper())
and make the code much shorter.