Beispiel #1
0
    def printScreen(self):
        """
		Provides the main functionality of AnswerListMenu
		Calls various methods to print answers to the screen and
		provides the user with the ability to select one of them

		Returns:
			A Dictionary object representing an answer to the question
		"""
        invalidInput = True
        while invalidInput:
            Terminal.clear()
            PostPrinter.printTitle(self.__question__)
            print("\n")
            self.printMenu()
            userInput = input("Enter Selection: ")
            if userInput.upper() == "EXIT" or userInput.upper() == "QUIT":
                return None
            try:
                userInput = int(userInput)
                if userInput < 1 or userInput > len(self.__menuItems__):
                    print("Input is out of range")
                else:
                    invalidInput = False
            except Exception:
                print("Entered input is invalid!")
            finally:
                input("Press Enter to Continue: ")
        userInput += -1
        return self.__menuItems__[userInput].Post
Beispiel #2
0
    def printTitle(post):
        """
		Prints the post in a formatted fashion

		Parameters:
			post:
				A dictionary object representing a post retrieved from the database

		"""
        Terminal.clear()
        usedKeys = [
            "Id", "Title", "Body", "Tags", "Score", "ViewCount",
            "CommentCount", "AnswerCount", "FavoriteCount", "ContentLicense",
            "CreationDate", "LastEditDate"
        ]

        Terminal.printCenter("----------Post----------")
        for key in usedKeys:
            if (key in post):
                PostPrinter.printKeyTitle(key)
                Terminal.printCenter(key + ": " + str(post[key]) + "\n")

        Terminal.printCenter("----------Misc Info----------")
        for key in post:
            if (key is not None and key not in usedKeys and key != "_id"):
                Terminal.printCenter(str(key) + ": " + str(post[key]) + "\n")
Beispiel #3
0
    def printScreen(self):
        """
		The main loop of the module. Prints the title and get's users input on whether they
		are registering or logging in
		"""
        while True:
            self.printTitle()
            userInput = input(
                "If you're an existing user, please enter your id. Otherwise, press enter: "
            ).strip()

            #if the user presses enter
            if userInput == "":
                return -1
            #if the user enters an id
            elif userInput.upper() != "EXIT":
                #TODO: User report
                print("Loading...")
                report = self.report(userInput)
                print("Number of questions posted: {}. Average score: {}.".
                      format(report["num_questions"], report["qavg_score"]))
                print(
                    "Number of answers posted: {}. Average score: {}.".format(
                        report["num_answers"], report["aavg_score"]))
                print("Number of votes: {}".format(report["num_votes"]))
                input("Press enter to continue...")
                return userInput

            elif userInput.upper().strip() == "EXIT":
                return None
            else:
                input("Invalid input, press enter to continue: ")
                Terminal.clear()
    def printScreen(self):
        """
		The main loop of Menu. Serves to print all menu items,
		gather userInput and ensure that input is valid

		Returns:
			userInput if the input provided is valid
			None if the input provided is invalid
		"""
        while True:
            self.printItems()
            userInput = input(
                "Type the number of the item you would like to select: ")
            try:
                userInput = int(userInput) - 1
                if (userInput <= self.__length__ - 1 and userInput >= 0):
                    return userInput
                else:
                    input("Invalid selection, press enter to continue: ")
            except Exception:
                try:
                    if userInput.upper() == "EXIT":
                        return None
                except Exception:
                    input("Invalid input, press enter to continue: ")
            Terminal.clear()
    def printTitleKeyword():
        """
		Prints identifying information telling the user what screen
		they are on and information about how to give keywords
		"""
        Terminal.clear()
        Terminal.printCenter("Search for Posts")
        Terminal.printCenter("Enter terms delimited by commas")
Beispiel #6
0
    def __init__(self):
        """
		Creates an instance of WelcomeScreen, which is the UI interface for welcoming users to the
		program.
		Parameters:
			N/A
		Returns:
			An instance of WelcomeScreen
		"""
        Terminal.clear()
    def __init__(self):
        """
		Creates an instance of Menu

		Parameters:
			terminal:
				A Terminal object allowing this module to interface
				with the OS terminal
		Returns:
			An instance of Menu
		"""
        self.__menuItems__ = []
        self.__length__ = 0

        Terminal.clear()