Skip to content

Instantly share code, notes, and snippets.

@erchn
Last active January 23, 2023 18:29
Show Gist options
  • Save erchn/029bbd79863c4b351445cff7742b7313 to your computer and use it in GitHub Desktop.
Save erchn/029bbd79863c4b351445cff7742b7313 to your computer and use it in GitHub Desktop.
Over engineered helper for Slack trolling
#!/usr/bin/env python3
import subprocess
from string import ascii_letters
from optparse import OptionParser
parser = OptionParser()
parser.add_option(
"-y",
dest="yellow",
default=False,
action="store_true",
help="Use alphabet-yellow instead of white",
)
parser.add_option(
"-a",
dest="alternate",
default=False,
action="store_true",
help="Use alphabet-yellow and alphabet-white alternatingly",
)
opts, args = parser.parse_args()
if opts.alternate:
color = ["yellow", "white"]
else:
color = ["yellow"] if opts.yellow else ["white"]
colorstr = ", ".join(set(color))
chars = {
**{"@": "at", "!": "exclamation", "#": "hash", "?": "question"},
**{x: x for x in ascii_letters},
}
def write_to_clipboard(output):
process = subprocess.Popen(
"pbcopy", env={"LANG": "en_US.UTF-8"}, stdin=subprocess.PIPE
)
process.communicate(output.encode("utf-8"))
inputstring = input("string to convert: ") if not args else args.pop()
out = "".join(
[
f":alphabet-{color[ind % len(color)]}-{chars[char]}:" if char in chars else char
for ind, char in enumerate(inputstring)
]
)
print(f"\n{out}\n")
try:
write_to_clipboard(out)
print(f"Alphabet {colorstr} string written to your clipboard!")
except FileNotFoundError as err:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment