def handle(self, *args, **options):
        # activate the language
        activate(settings.LANGUAGE_CODE)

        daemon = options['daemon']
        cron = options['cron']

        assert not (daemon and cron), "You cannot both choose cron and daemon options"

        self.logger = logging.getLogger('django_nyt')

        if not self.logger.handlers:
            if daemon:
                handler = logging.FileHandler(filename=options['log'])
            else:
                handler = logging.StreamHandler(self.stdout)
            self.logger.addHandler(handler)
            self.logger.setLevel(logging.INFO)

        self.logger.info("Starting django_nyt e-mail dispatcher")

        if not nyt_settings.SEND_EMAILS:
            print("E-mails disabled - quitting.")
            sys.exit()

        # Run as daemon, ie. fork the process
        if daemon:
            self.logger.info("Daemon mode enabled, forking")
            try:
                fpid = os.fork()
                if fpid > 0:
                    # Running as daemon now. PID is fpid
                    self.logger.info("PID: %s" % str(fpid))
                    pid_file = open(options['pid'], "w")
                    pid_file.write(str(fpid))
                    pid_file.close()
                    if not options['no_sys_exit']:
                        sys.exit(0)
            except OSError as e:
                sys.stderr.write(
                    "fork failed: %d (%s)\n" %
                    (e.errno, e.strerror))
                sys.exit(1)

        # create a connection to smtp server for reuse
        try:
            connection = mail.get_connection()
        except:
            self.logger.error("Could get a mail connection")
            raise

        if cron:
            self.send_mails(connection)
        else:
            if not daemon:
                print("Entering send-loop, CTRL+C to exit")
            try:
                self.send_loop(connection, int(options['sleep_time']))
            except KeyboardInterrupt:
                print("\nQuitting...")

        # deactivate the language
        deactivate()
dataset/ETHPy150Open benjaoming/django-nyt/django_nyt/management/commands/notifymail.py/Command.handle/original