Skip to content

Instantly share code, notes, and snippets.

@szero
Last active January 24, 2020 01:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save szero/033a3a3ce25b9395c8dea84f8e11340f to your computer and use it in GitHub Desktop.
Save szero/033a3a3ce25b9395c8dea84f8e11340f to your computer and use it in GitHub Desktop.
Upload nice text file meem to volafile

Steps for posting your based meem

  1. Go here. You must use ANSI Shadow font.
  2. Type your text and copy it.
  3. Save it as text file or pass the clipboard directly to script.

Dependencies

Example usage:

xsel -ob | ./volafilememe.py BEEPi

./volafilememe.py "shit room, kys.txt" HF33Go

#!/usr/bin/env python3
import sys
import os
import re
from tempfile import TemporaryDirectory
from subprocess import run
class FilenameTooLongError(OSError):
pass
def list_duplicates(seq):
seen = set()
seen_add = seen.add
return [idx for idx, item in enumerate(seq) if item in seen or seen_add(item)]
room, memes = [], []
if sys.stdin.isatty():
with open(os.path.abspath(sys.argv[1]), "r") as boi:
memes = [l for l in boi.readlines()]
try:
if sys.argv[2]:
room.append("-r")
room.append(sys.argv[2])
except IndexError:
pass
else:
memes = [l for l in sys.stdin.readlines()]
try:
if sys.argv[1]:
room.append("-r")
room.append(sys.argv[1])
except IndexError:
pass
for m in memes:
if len(m.encode("utf-8")) > 250: # 255 - 5 bytes for additional filename later
raise FilenameTooLongError(
"Ey boi, max length of lelnix filename is 255"
"bytes, make your text shorter if you want your meme reign supreme."
)
box = re.compile(r"[\u2500-\u257F]", re.I | re.M)
for i, l in enumerate(memes):
memes[i] = box.sub("░", l).strip().replace(" ", "░")
# remove empty lines
memes = [m for m in memes if m]
# remove double lines and trailing line at the bottom
for i, l in enumerate(memes):
if (l == len(l) * l[0]) and (memes[i + 1] == len(memes[i + 1]) * memes[i + 1][0]):
memes.pop(i)
if memes[-1] == len(memes[-1]) * memes[-1][0]:
memes.pop()
# add some invis character to the end so we can have filenames that are the same
# also dat SO doe: https://stackoverflow.com/a/23645451/8774873
invis_char = " \u200C"
for idx in list_duplicates(memes):
memes[idx] += invis_char
invis_char = f"{invis_char}\u200C"
with TemporaryDirectory() as d:
meme_files = []
for i in memes[::-1]:
path = d + "/" + i
try:
with open(path, "w") as nuthing:
pass
except Exception:
print(
"Can't make it dude, are you sure you have ASCII stuff "
"consisting of box drawing characters in your clipboard/file?",
file=sys.stderr,
)
sys.exit(1)
meme_files.append(path)
run(["volaupload.sh", *room, *meme_files])
@szero
Copy link
Author

szero commented Oct 25, 2018

Doesn't work as of now. Seems like lain disallows box-drawing characters in filenames now.

@szero
Copy link
Author

szero commented Oct 1, 2019

As of now works again, give it a whirl bois.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment