Last active
September 27, 2018 20:50
-
-
Save knowsuchagency/6b335722fa8806a30ffff56822290d02 to your computer and use it in GitHub Desktop.
email script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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