Skip to content

Instantly share code, notes, and snippets.

@knowsuchagency knowsuchagency/email.py
Last active Sep 27, 2018

Embed
What would you like to do?
email script
#!/usr/bin/env python3
import subprocess as sp
import io
import os
def paste_emails_to_clipboard(string, report=None):
"""
search the string for emails and copy them to clipboard to be pasted into gmail
"""
if report is not None:
print(f'gathering emails for {report}')
print('------')
emails = set(l.strip() for l in string.splitlines() if '@' in l)
print('comments:')
for line in string.splitlines():
if line.strip().startswith('#'):
print(line)
print('--------')
output = (',' + os.linesep).join(emails)
sp.run(['pbcopy'], input=bytes(output, encoding='utf8'))
print('all set, paste to gmail receivers list')
print('type `pbpaste` in terminal to verify')
print('--------')
print(output)
if __name__ == '__main__':
import sys
from pathlib import Path
if len(sys.argv) > 1:
file = Path(sys.argv[1])
with file.open() as fp:
paste_emails_to_clipboard(fp.read(), file.stem)
else:
clipboard = sp.run(['pbpaste'], stdout=sp.PIPE).stdout.decode()
paste_emails_to_clipboard(clipboard)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.