| LEFT | RIGHT |
| 1 # coding: utf-8 | 1 # coding: utf-8 |
| 2 | 2 |
| 3 # This file is part of the Adblock Plus web scripts, | 3 # This file is part of the Adblock Plus web scripts, |
| 4 # Copyright (C) 2006-2015 Eyeo GmbH | 4 # Copyright (C) 2006-2015 Eyeo GmbH |
| 5 # | 5 # |
| 6 # Adblock Plus is free software: you can redistribute it and/or modify | 6 # Adblock Plus is free software: you can redistribute it and/or modify |
| 7 # it under the terms of the GNU General Public License version 3 as | 7 # it under the terms of the GNU General Public License version 3 as |
| 8 # published by the Free Software Foundation. | 8 # published by the Free Software Foundation. |
| 9 # | 9 # |
| 10 # Adblock Plus is distributed in the hope that it will be useful, | 10 # Adblock Plus is distributed in the hope that it will be useful, |
| 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 # GNU General Public License for more details. | 13 # GNU General Public License for more details. |
| 14 # | 14 # |
| 15 # You should have received a copy of the GNU General Public License | 15 # You should have received a copy of the GNU General Public License |
| 16 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 16 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 17 | 17 |
| 18 import sys | 18 import sys |
| 19 import argparse | 19 import argparse |
| 20 import logging | 20 import logging |
| 21 | 21 |
| 22 from sitescripts.utils import sendMail | 22 from sitescripts.utils import get_template, sendMail |
| 23 | 23 |
| 24 parser = argparse.ArgumentParser(description='Renders the given email template ' | 24 parser = argparse.ArgumentParser(description='Renders the given email template ' |
| 25 'and dispatches emails to the ' | 25 'and dispatches emails to the ' |
| 26 'addresses given on stdin') | 26 'addresses given on stdin') |
| 27 parser.add_argument('template') | 27 parser.add_argument('template') |
| 28 parser.add_argument('--log-level', default='INFO') | 28 parser.add_argument('--log-level', default='INFO') |
| 29 | 29 |
| 30 if __name__ == '__main__': | 30 if __name__ == '__main__': |
| 31 args = parser.parse_args() | 31 args = parser.parse_args() |
| 32 logging.basicConfig(level=args.log_level) | 32 logging.basicConfig(level=args.log_level) |
| 33 template = get_template(args.template, False) |
| 33 | 34 |
| 34 for recipient in sys.stdin: | 35 for recipient in sys.stdin: |
| 35 recipient = recipient.strip() | 36 recipient = recipient.strip() |
| 36 try: | 37 try: |
| 37 sendMail(args.template, {'recipient': recipient}) | 38 sendMail(template, {'recipient': recipient}) |
| 38 except Exception: | 39 except Exception: |
| 39 logging.error('Failed to send email to %r', recipient, exc_info=True) | 40 logging.error('Failed to send email to %r', recipient, exc_info=True) |
| 40 else: | 41 else: |
| 41 logging.info('Sent email to %r', recipient) | 42 logging.info('Sent email to %r', recipient) |
| LEFT | RIGHT |