Skip to content

Instantly share code, notes, and snippets.

@glasnt
Last active August 25, 2016 16:22
Show Gist options
  • Save glasnt/b6ef7948fdcae8c200043ac8529778a9 to your computer and use it in GitHub Desktop.
Save glasnt/b6ef7948fdcae8c200043ac8529778a9 to your computer and use it in GitHub Desktop.
๐Ÿ‡ทโ€‹๐Ÿ‡ชโ€‹๐Ÿ‡ฌโ€‹๐Ÿ‡ฎโ€‹๐Ÿ‡ดโ€‹๐Ÿ‡ณโ€‹๐Ÿ‡ฆโ€‹๐Ÿ‡ฑโ€‹ โ€‹๐Ÿ‡ฎโ€‹๐Ÿ‡ณโ€‹๐Ÿ‡ฉโ€‹๐Ÿ‡ฎโ€‹๐Ÿ‡จโ€‹๐Ÿ‡ฆโ€‹๐Ÿ‡นโ€‹๐Ÿ‡ดโ€‹๐Ÿ‡ทโ€‹ โ€‹๐Ÿ‡จโ€‹๐Ÿ‡ญโ€‹๐Ÿ‡ฆโ€‹๐Ÿ‡ทโ€‹๐Ÿ‡ฆโ€‹๐Ÿ‡จโ€‹๐Ÿ‡นโ€‹๐Ÿ‡ชโ€‹๐Ÿ‡ทโ€‹๐Ÿ‡ธโ€‹ โ€‹๐Ÿ‡ฆโ€‹๐Ÿ‡ธโ€‹ โ€‹๐Ÿ‡ฆโ€‹ โ€‹๐Ÿ‡ธโ€‹๐Ÿ‡ชโ€‹๐Ÿ‡ทโ€‹๐Ÿ‡ปโ€‹๐Ÿ‡ฎโ€‹๐Ÿ‡จโ€‹๐Ÿ‡ช
"""
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)
@salty-horse
Copy link

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 " ".

@AnthonyBriggs
Copy link

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