cli/streamingphish/streamingphish/cli.py
def _train_classifier(self):
        """
        Train classifier, compute metrics, and prompt the user for two decisions:
            - keep the classifier? y/n
                - if yes, ask user to name it.
                - validate name is available in the database, then write metrics and classifier.
            - activate the classifier? y/n
                - if yes, update the active classifier name in the config with the new name.
        """
        # In the future, could make a recommendation on which classifier to deploy.
        artifacts = PhishTrainer().generate_model()
        tqdm.tqdm.write("The metrics from the newly trained classifier are as follows:")
        tqdm.tqdm.write(json.dumps(artifacts['metrics'], indent=4))

        while True:
            keep = input("Would you like to keep the classifier? [y/N] ").lower()
            if keep not in VALID_ANSWERS:
                tqdm.tqdm.write("Sorry, please respond with 'yes' or 'no'.")
                continue
            else:
                # Got a good answer - break out of this and proceed.
                break

        if keep in YES_ANSWERS:
            # Prompt the user for a classifier name, validate against DB to ensure it's available.
            # while loop or try/except.
            while True:
                classifier_name = input("Please enter a name (no spaces) for the"
                                        " classifier: ").lower()

                # Check for spaces.
                if ' ' in classifier_name:
                    tqdm.tqdm.write("Sorry, a space was found in the name. Please try again.")
                    continue

                # Check to see if this name is available in the database.
                for clf in self._phish_db.available_classifiers():
                    if clf == classifier_name:
                        overwrite = input("Sorry, a classifier with the same name already"
                                          " exists in the database. Would you like to "
                                          "overwrite it? [y/N]".lower())
                        if overwrite in VALID_ANSWERS:
                            # Delete existing classifier.
                            self._phish_db.delete_classifier(classifier_name)
                        else:
                            # User doesn't want to overwrite but wants to keep the classifier. Let
                            # them pick a new name, don't break.
                            continue

                # No spaces and name is available - proceed with persisting to database.
                artifacts['classifier_name'] = classifier_name
                self._phish_db.save_classifier(artifacts)
                break
        else:
            tqdm.tqdm.write("[+] Not saving - returning to main menu.")
            return

        # Only way to get this far is by saving a classifier wanted by the user.
        # Now check to see if they want to activate it.
        while True:
            activate = input("Would you like to activate the classifier? [y/N] ").lower()
            if keep not in VALID_ANSWERS:
                tqdm.tqdm.write("Sorry, please respond with 'yes' or 'no'.")
                continue
            else:
                # Got a good answer - break out of this and proceed.
                break

        if activate in YES_ANSWERS:
            try:
                self._phish_config.active_classifier = classifier_name
            except ValueError as error:
                tqdm.tqdm.write("[-] An error occurred during activation: {}".format(error))
        else:
            tqdm.tqdm.write("[+] Not activating - returning to main menu.")

        Train classifier, compute metrics, and prompt the user for two decisions:
            - keep the classifier? y/n
                - if yes, ask user to name it.
                - validate name is available in the database, then write metrics and classifier.
            - activate the classifier? y/n
                - if yes, update the active classifier name in the config with the new name.
        
Train classifier, compute metrics, and prompt the user for two decisions:
keep the classifier. y/n
if yes, ask user to name it.
validate name is available in the database, then write metrics and classifier.
activate the classifier. y/n
if yes, update the active classifier name in the config with the new name.
Train classifier compute metrics and prompt the user for two decisions : keep the classifier . y / n if yes ask user to name it . validate name is available in the database then write metrics and classifier . activate the classifier . y / n if yes update the active classifier name in the config with the new name .
def _train_classifier(self):
        artifacts = PhishTrainer().generate_model()
        tqdm.tqdm.write("The metrics from the newly trained classifier are as follows:")
        tqdm.tqdm.write(json.dumps(artifacts['metrics'], indent=4))
        while True:
            keep = input("Would you like to keep the classifier? [y/N] ").lower()
            if keep not in VALID_ANSWERS:
                tqdm.tqdm.write("Sorry, please respond with 'yes' or 'no'.")
                continue
            else:
                break
        if keep in YES_ANSWERS:
            while True:
                classifier_name = input("Please enter a name (no spaces) for the"
                                        " classifier: ").lower()
                if ' ' in classifier_name:
                    tqdm.tqdm.write("Sorry, a space was found in the name. Please try again.")
                    continue
                for clf in self._phish_db.available_classifiers():
                    if clf == classifier_name:
                        overwrite = input("Sorry, a classifier with the same name already"
                                          " exists in the database. Would you like to "
                                          "overwrite it? [y/N]".lower())
                        if overwrite in VALID_ANSWERS:
                            self._phish_db.delete_classifier(classifier_name)
                        else:
                            continue
                artifacts['classifier_name'] = classifier_name
                self._phish_db.save_classifier(artifacts)
                break
        else:
            tqdm.tqdm.write("[+] Not saving - returning to main menu.")
            return
        while True:
            activate = input("Would you like to activate the classifier? [y/N] ").lower()
            if keep not in VALID_ANSWERS:
                tqdm.tqdm.write("Sorry, please respond with 'yes' or 'no'.")
                continue
            else:
                break
        if activate in YES_ANSWERS:
            try:
                self._phish_config.active_classifier = classifier_name
            except ValueError as error:
                tqdm.tqdm.write("[-] An error occurred during activation: {}".format(error))
        else:
            tqdm.tqdm.write("[+] Not activating - returning to main menu.")
def _train_classifier ( self ) : artifacts = PhishTrainer ( ) . generate_model ( ) tqdm . tqdm . write ( "The metrics from the newly trained classifier are as follows:" ) tqdm . tqdm . write ( json . dumps ( artifacts [ 'metrics' ] , indent = 4 ) ) while True : keep = input ( "Would you like to keep the classifier? [y/N] " ) . lower ( ) if keep not in VALID_ANSWERS : tqdm . tqdm . write ( "Sorry, please respond with 'yes' or 'no'." ) continue else : break if keep in YES_ANSWERS : while True : classifier_name = input ( "Please enter a name (no spaces) for the" " classifier: " ) . lower ( ) if ' ' in classifier_name : tqdm . tqdm . write ( "Sorry, a space was found in the name. Please try again." ) continue for clf in self . _phish_db . available_classifiers ( ) : if clf == classifier_name : overwrite = input ( "Sorry, a classifier with the same name already" " exists in the database. Would you like to " "overwrite it? [y/N]" . lower ( ) ) if overwrite in VALID_ANSWERS : self . _phish_db . delete_classifier ( classifier_name ) else : continue artifacts [ 'classifier_name' ] = classifier_name self . _phish_db . save_classifier ( artifacts ) break else : tqdm . tqdm . write ( "[+] Not saving - returning to main menu." ) return while True : activate = input ( "Would you like to activate the classifier? [y/N] " ) . lower ( ) if keep not in VALID_ANSWERS : tqdm . tqdm . write ( "Sorry, please respond with 'yes' or 'no'." ) continue else : break if activate in YES_ANSWERS : try : self . _phish_config . active_classifier = classifier_name except ValueError as error : tqdm . tqdm . write ( "[-] An error occurred during activation: {}" . format ( error ) ) else : tqdm . tqdm . write ( "[+] Not activating - returning to main menu." )
Train classifier, compute metrics, and prompt the user for two decisions:
 keep the classifier?
Train classifier compute metrics and prompt the user for two decisions : keep the classifier?
"""
        Train classifier, compute metrics, and prompt the user for two decisions:
            - keep the classifier? y/n
                - if yes, ask user to name it.
                - validate name is available in the database, then write metrics and classifier.
            - activate the classifier? y/n
                - if yes, update the active classifier name in the config with the new name.
        """ # In the future, could make a recommendation on which classifier to deploy. # Got a good answer - break out of this and proceed. # Prompt the user for a classifier name, validate against DB to ensure it's available. # while loop or try/except. # Check for spaces. # Check to see if this name is available in the database. # Delete existing classifier. # User doesn't want to overwrite but wants to keep the classifier. Let # them pick a new name, don't break. # No spaces and name is available - proceed with persisting to database. # Only way to get this far is by saving a classifier wanted by the user. # Now check to see if they want to activate it. # Got a good answer - break out of this and proceed.
self