from __future__ import print_function import datetime, subprocess, tempfile, textwrap, sys # NOTE: THIS IS REALLY BAD CODE AND WILL PROBABLY BREAK HORRIBLY OK?? # INSTRUCTIONS: # 1. install "toot" by running "pip install --user toot" or something # 2. login to it with "toot login" or "toot login_browser" or something # 3. fill in these variables ZEPHYR_CLASS = (PUT A STRING LITERAL HERE) ZEPHYR_ZSIG = (PUT A STRING LITERAL HERE) # 4. run this script whenever you want to zephyr and toot # write "-i (the instance you want to post to)" on the first line and then your # zephyr on the rest, or if you forget it'll prompt you for the instance try: input = raw_input except NameError: pass tempfile = tempfile.NamedTemporaryFile() p = subprocess.Popen(('vim', tempfile.name)) p.wait() lines = tempfile.readlines() if not lines: print('Aborted') sys.exit() print(lines) if lines[0].startswith('-i '): _, instance = lines[0].split(None, 1) lines = lines[1:] else: instance = input('Instance? ') instance = instance.strip() text = '\n'.join(lines) print("Length:", len(text)) print("Zephyr instance:", instance) zephyr_lines = textwrap.wrap(text) zephyr_text = '\n'.join(zephyr_lines) print("Wrapped:") print(zephyr_text) print("Does this look good? (y/n) ", end="") if input().startswith("y"): print("Sending zephyr...") zargs = ["zwrite", "-c", ZEPHYR_CLASS, "-i", instance, "-s", ZEPHYR_ZSIG] zproc = subprocess.Popen(zargs, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) zout, zerr = zproc.communicate(zephyr_text) if zout: print("ZEPHYR OUT") print(zout) if zerr: print("ZEPHYR ERROR") print(zerr) print("Sending toot...") targs = ["toot", "post"] tproc = subprocess.Popen(targs, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) tout, terr = tproc.communicate(text) if tout: print("TOOT OUT") print(tout) if terr: print("TOOT ERROR") print(terr) else: print("Canceled")