コード例 #1
0
def FirstMenu():
    # initialize the counter
    counter = 0
    # While loop to check the number of invalid attempts by the user
    while counter < 3:
        # Print the welcome message
        print("****** Welcome to Zendesk Ticket Viewer ******")
        # Display the menu
        # Get user input
        start = input("Please type S to start or Q to quit: ")
        if start.upper() == 'Q':
            print("Closing the program...")
            # Sleep for 2 seconds before closing the application
            sleep(2)
            # Set counter to 4 in order to quit the while loop
            counter = 4
            # Return false to close the program
            quit()
        elif start.upper() == 'S':
            # return True to start next loop
            return True
            # Set counter to 4 in order to quit the while loop
            counter = 4
            clear()
        else:
            # Increment the counter if no option matches
            counter += 1
            clear()
            # Display Error message
            print("Invalid Input. Please try again."
                  "\nAttempts remaining: " + str(3 - counter))

    # If the user made 3 invalid attempts, close the program.
    InvalidAttempts(counter)
コード例 #2
0
ファイル: GetLogin.py プロジェクト: pekinpah/ZendeskChallenge
def AutoLogin():
    # Decode the credentials
    credentials = base64.b64decode(
        b'YWJoaXNoZWtwYWh1amFAaG90bWFpbC5jb20=').decode(
            'utf-8'), base64.b64decode(b'UElSQVRFU29mVEhFY2FyaWJiZWFu').decode(
                'utf-8')
    # Create session
    session = requests.Session()
    # Authenticate test user
    session.auth = credentials
    zendesk = 'https://thedottedline.zendesk.com/api/v2/tickets.json?page='
    url = zendesk + '1'
    response = session.get(url)
    if response.status_code != 200:
        # Call the error code method from errorCode.py
        ErrorCodes(response.status_code)
        # Sleep for 5 seconds before clearing screen
        sleep(5)
        clear()
    else:
        clear()
        # Check the number of pages
        DATA = response.json()
        total_records = DATA['count']
        # Calculate the number of pages
        Total_Pages = int(total_records / 100) + 1
        # If more than 1 page(100 tickets)
        DataArray = [DATA] * (total_records)
        RecordArray = [DATA] * Total_Pages

        # Initialise counters
        PageCount = 1
        recordcounter = 0
        # Put all the data in arrays
        while recordcounter < total_records:
            for records in RecordArray:
                zendesk = 'https://thedottedline.zendesk.com/api/v2/tickets.json?page='
                url = zendesk + str(PageCount)
                response = session.get(url)
                # Get all the ticket records
                records = response.json()
                # Get individual ticket records
                for data in records['tickets']:
                    DataArray[recordcounter] = data
                    # Increment the record counter
                    recordcounter += 1
                # Increment to next page
                PageCount += 1
        # display a message if no tickets were found
            if total_records == 0:
                print(
                    'this account has zero tickets. requsting tickets dislay will result in blank output'
                )
        # Return the collected tickets
        return DataArray
コード例 #3
0
def InvalidAttempts(counter):
    if counter == 3:
        # Clear the screem
        clear()
        # Display error message
        print("You have exceeded maximum number of attempts."
              "\nClosing the application...")
        # Sleep for 2 seconds before closing the application
        sleep(2)
        # Close the application
        quit()
コード例 #4
0
def SecondMenu():
    # initialise counter
    counter = 0
    # While loop to keep the incorrect attempts in check
    while counter < 3:
        clear()
        # Display the menu
        # Get user input
        print("Select option 1 to auto login using a test account"
              "\nSelect option 2 to enter your log in details"
              "\nSelect option 3 to close the application")
        option = input("Enter your choice: ")
        # Try block to catch input type mismatch
        try:
            choice = int(option)
            if choice == 1:     # User selects auto login
                # Set counter to 4 in order to quit the while loop
                counter = 4
                # Return true if user selects Auto login
                return True
            elif choice == 2:   # User Selects manual login
                # Set counter to 4 in order to quit the while loop
                counter = 4
                # Return false if user selects manual login
                return False
            elif choice == 3:   # user wants to close the application
                # Set counter to 4 in order to quit the while loop
                counter = 4
                quit()
            else:
                # If user's choice is out of range
                # increment the counter
                counter += 1
                # Display Error message
                print("Invalid value. Please select one option out of 1, 2 and 3"
                      "\nAttempts remaining: " + str(3 - counter))
        # Except block to catch value Error (if input is different that required data type)
        except ValueError:
            # Increment the counter
            counter += 1
            # Print error message for the user
            print("Invalid value. Please select one option out of 1, 2 and 3"
                  "\nAttempts remaining: " + str(3 - counter))
            # Sleep for 2 seconds before clearing the screen
            sleep(2)
            clear()

    # If the user made 3 invalid attempts, close the program.
    InvalidAttempts(counter)
コード例 #5
0
def DisplayAll(DataArray):
    clear()
    print("\n\n")
    # For loop to get all the elements of the array to print the required data
    for ticket in DataArray:
        # Tabulate and separate all the tickets
        print(
            "--------------------------------------------------------------------------"
        )
        print('Ticket ID: {}'.format(ticket['id']))
        print(
            "--------------------------------------------------------------------------"
        )
        print("Ticket Subject: {}\n"
              "Ticket Status: {}\n"
              "Requester ID: {}\n"
              "Submitter ID: {}".format(ticket['raw_subject'],
                                        ticket['status'],
                                        ticket['submitter_id'],
                                        ticket['assignee_id']))
        print(
            "--------------------------------------------------------------------------\n\n"
        )
コード例 #6
0
def ThirdMenu():
    # Initialise the counter
    counter = 0
    while counter < 3:
        # Display the menu
        option = input("Please select one of the following options:"
                       "\n\tSelect option 1 to display all the tickets"
                       "\n\tSelect option 2 to display a specific ticket"
                       "\n\tSelect option 3 to logout and try again"
                       "\n\tSelect option 4 to close the application."
                       "\n\tYour Choice: ")
        # Try block to catch input type mismatch
        try:
            choice = int(option)
            if choice == 1:     # User wants to display all the tickets
                clear()
                # Set counter to 4 in order to quit the while loop
                counter = 4
                return choice
            elif choice == 2:   # User wants to Select a specific ticket number
                # Set counter to 4 in order to quit the while loop
                counter = 4
                return choice
            elif choice == 3:   # User wants to try using another account/domain
                clear()
                # Set counter to 4 in order to quit the while loop
                counter = 4
                print("Logging out...")
                # Sleep for 2 seconds before clearing screen
                sleep(2)
                clear()
                return choice
            elif choice == 4:   # User wants to close the application
                clear()
                counter = 4
                print("Closing the application...")
                # Sleep for 2 seconds before closing the application
                sleep(2)
                quit()
            else:               # user has entered out of range option
                clear()
                # Increment the counter
                counter += 1
                # Display the error message
                print("Invalid choice. Please try again"
                      "\nAttempts remaining: " + str(3 - counter))
        # Except block to catch value Error (if input is different that required data type)
        except ValueError:
            # Increment the counter
            counter += 1
            # Display te error message
            print("Invalid value. Please select one option out of 1, 2, 3 and 4"
                  "\nAttempts remaining: " + str(3 - counter))
            # Add 2 second delay before clearing the screen
            sleep(2)
            clear()

    # If the user made 3 invalid attempts, close the program.
    InvalidAttempts(counter)
コード例 #7
0
def DisplaySelected(DataArray):
    clear()
    # Initialise the counters
    itemCounter = 0
    counter = 0
    for temp in DataArray:
        # counter to get the total number of tickets
        itemCounter += 1
    # While loop to limit number of attempts
    while counter < 3:
        option = input("Total tickets: " + str(itemCounter) +
                       "\nPlease enter the ticket ID/number to be searched: ")
        # Try block to catch input type mismatch
        try:
            choice = int(option)
            if choice <= itemCounter and choice > 0:
                clear()
                for ticket in DataArray:
                    for id in ticket.values():
                        # If the id is fount in the tickets
                        # Print the required ticket
                        if id == choice:
                            # Tabulate and separate all the tickets
                            print(
                                "\n\n--------------------------------------------------------------------------"
                            )
                            print('Ticket ID: {}'.format(ticket['id']))
                            print(
                                "--------------------------------------------------------------------------"
                            )
                            print("Ticket Subject: {}\n"
                                  "Ticket Status: {}\n"
                                  "Requester ID: {}\n"
                                  "Submitter ID: {}\n"
                                  "Ticket Description: {}".format(
                                      ticket['raw_subject'], ticket['status'],
                                      ticket['submitter_id'],
                                      ticket['assignee_id'],
                                      ticket['description']))
                            print(
                                "--------------------------------------------------------------------------\n\n"
                            )
                            # Set counter to 4 in order to quit the while loop
                            counter = 4
                            break
            # If the user entered out of range value
            elif choice > itemCounter or choice <= 0:
                # increment the attempt counter
                counter += 1
                # display error message
                print(
                    "The id you have entered is out of range. Please try again."
                    "\nYou selected: " + str(choice) +
                    "\nNumber of attempts remaining: " + str(3 - counter))
        # Except block to catch value Error (if input is different that required data type)
        except ValueError:
            counter += 1
            print("Invalid value. Please select a valid value"
                  "\nAttempts remaining: " + str(3 - counter))
            # Sleep for 2 seconds before clearing screen
            sleep(2)
            clear()

    # If the user made 3 invalid attempts, close the program.
    InvalidAttempts(counter)
コード例 #8
0
ファイル: GetLogin.py プロジェクト: pekinpah/ZendeskChallenge
def Login():
    # Set counter to 0
    counter = 0
    # If user does not make 3 incorrect attempts continue
    while counter < 3:
        print('https://{DomainName}.zendesk.com')
        # Get user's login details
        domain = input("Please enter the domain name (without curly braces): ")
        email = input("Please enter your email address: ")
        password = getpass("Please enter your password: "******"Please check the data you entered."
                  "\nDomain Name: " + domain + "\nEmail ID: " + email +
                  "\nPassword: "******"\nTotal attempts remaining: " +
                  str(3 - counter))
        else:
            clear()
            # Check the number of pages
            DATA = response.json()
            total_records = DATA['count']
            # Calculate the number of pages
            Total_Pages = int(total_records / 100) + 1
            # If more than 1 page(100 tickets)
            DataArray = [DATA] * (total_records)
            RecordArray = [DATA] * Total_Pages
            PageCount = 1
            recordcounter = 0
            # Put all the data in arrays
            while recordcounter < total_records:
                for records in RecordArray:
                    zendesk = 'https://' + domain + '.zendesk.com/api/v2/tickets.json?page='
                    url = zendesk + str(PageCount)
                    response = session.get(url)
                    # get all the ticket records
                    records = response.json()
                    # Get individual ticket records
                    for data in records['tickets']:
                        DataArray[recordcounter] = data
                        # Increment the record counter
                        recordcounter += 1
                    # Increment the to next page
                    PageCount += 1
            # Set counter to 4 to break while loop
            counter = 4
            # display a message if no tickets were found
            if total_records == 0:
                print(
                    'this account has zero tickets. requsting tickets dislay will result in blank output'
                )
            # Return the ticket data
            return DataArray

    # If the user made 3 invalid attempts, close the program.
    InvalidAttempts(counter)