Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redoing the menus to clean up the code #39

Open
naveci opened this issue Dec 4, 2019 · 5 comments
Open

Redoing the menus to clean up the code #39

naveci opened this issue Dec 4, 2019 · 5 comments
Assignees
Labels
Code Improvement Improves the code in some way

Comments

@naveci
Copy link
Contributor

naveci commented Dec 4, 2019

What is the feature that you are requesting?
I'm thinking of redoing the menus to clean up the code. By putting the contents in dictionaries, we could generate the menus more consistently. It would allow us to take a lot of the printing code out. I haven't counted lines, but it might be quite a lot.
Another advantage: adding a new function only requires an edit in one part of the document - the dictionary.

What's your take?

Additional information
An example is listed below. I do need to really think about this carefully as it won't be entirely as easy as the example code below.

Is your feature request related to a problem? Please describe.
N/A

Additional context
Current code example for the phishing menu:

def phishingMenu():
    print("\n --------------------------------- ")
    print("          P H I S H I N G          ")
    print(" --------------------------------- ")
    print(" What would you like to do? ")
    print(" OPTION 1: Analyze an Email ")
    print(" OPTION 2: Analyze an Email Address for Known Activity")
    print(" OPTION 3: Generate an Email Template based on Analysis")
    print(" OPTION 4: Analyze an URL with Phishtank")
    print(" OPTION 9: HaveIBeenPwned")
    print(" OPTION 0: Exit to Main Menu")
    phishingSwitch(input())

def phishingSwitch(choice):
    if choice == '1':
        analyzePhish()
    if choice == '2':
        analyzeEmailInput()
    if choice == '3':
        emailTemplateGen()
    if choice == '4':
        phishtankModule()
    if choice == '9':
        haveIBeenPwned()
    else:
        mainMenu()

We could shorten this to the following dict:

phishingMenuDict = {
    # Number is the keyboard shortcut, name is the functionname, desc is what the users see as menu option
    0: {"name":"exit", "desc":"back to main menu"},
    1: {"name":"analyzePhish", "desc":"Analyze an Email"},
    2: {"name":"analyzeEmailInput", "desc":"Analyze an Email Address for Known Activity"},
    3: {"name":"emailTemplateGen", "desc":"Generate an Email Template based on Analysis"},
    4: {"name":"phishtankModule", "desc":"Analyze an URL with Phishtank"}
    9: {"name":"haveIBeenPwned", "desc":"HaveIBeenPwned"}
}

Then we need to write 1 function to generate a menu so that we could throw multiple of these dicts to that function. some semi code:

def menuGenerator(menuName):
    print(20 * "-")
    if menu = "main":
        print(mainMenuDict["title"])
    else:
        print(someOtherMenuDictName)
    print((20 * "-") + "\n")

    # That's the printing covered, below is the menu selection
    for menuItem in someOtherMenuDict:
        # Prints something like    Option 1: Analyze an Email
        print("  Option " + menuItem + ": " + someOtherMenuDictName["desc"])
    
    userChoice = input()
    # Check user input
    if userChoice in someOtherMenuDict:
        someOtherMenuDict(userChoice)
    else:
        print("Invalid option, please choose again")
@TheresAFewConors TheresAFewConors added the Code Improvement Improves the code in some way label Dec 5, 2019
@TheresAFewConors
Copy link
Owner

Seems like a useful update. The menu does need to be redone since the project has grown a lot since version 1.0 into something more maintainable for the future.

@naveci
Copy link
Contributor Author

naveci commented Dec 20, 2019

Is it possible to create a separate branch for dev?
Then I can PR against that, which allows a bit more testing before merging into master. I've found a nice way of building the menu's, but it's definitely an overhaul.

@TheresAFewConors
Copy link
Owner

@naveci I created a dev branch that should fulfill what you need.

@naveci
Copy link
Contributor Author

naveci commented Feb 7, 2020

First version is up:
https://github.com/naveci/Sooty/tree/menu-redesign

Still need to fix a few minor things (press any key to continue) etc.
Also looking at a slightly nicer representation like your current one.
I think the code is already a bit cleaner and lost about 100 lines (give or take).

Will merge with dev when i feel it's ready =)

@TheresAFewConors
Copy link
Owner

@naveci no rush, I'm in the midst of a code refactor and moving some of the modules around on Dev to clean up and improve usability atm.

@naveci naveci mentioned this issue Feb 10, 2020
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Code Improvement Improves the code in some way
Projects
None yet
Development

No branches or pull requests

2 participants