Exemplo n.º 1
0
def get_duration():
    """duration grab input"""
    while True:
        duration = input('please input the duration '
                         'of the task in minutes: ')
        # tests input against regex pattern if pattern  test
        durpattern = re.compile("(\d+)")
        durmatch = durpattern.fullmatch(duration)
        # if pattern fails test
        if not durmatch:
            print('this is not an appropriate format')
        # if pattern passes loop breaks and values stored
        else:
            utility = Utility()
            duration = utility.str2time(duration)
            clear()
            return duration
Exemplo n.º 2
0
    def user_search(self):
        """
        user_search gathers and stores user input related to search entries

        handles user data gathering and storage for search by date, duration
        regex pattern and exact match. once data is gathered and stored
        a WorkLog object is instantiated and the data passed to the relevant
        search method of worklog object

        """
        while True:
            # prompt choose search method
            search_option = input('please choose a search option: ')
            # if user provides a invalid response to prompt
            if search_option not in ('a', 'b', 'c', 'd', 'e'):
                print('this is not an available option')
            # if response valid loop will break
            else:
                break

        # if date prompt for date get input
        if search_option == 'a':
            clear()
            # begin loop for entry search by date data collection

            while True:

                date = input('please input a date to search '
                             'in the format yyyy/mm/dd: ')
                # tests input against  regex pattern
                pattern = re.compile("(\d{4}\/\d{2}\/\d{2})")
                match = pattern.fullmatch(date)
                # if pattern fails test
                # messsage will prompt until correct format recieved
                if not match:
                    print('this is not an appropriate format')
                    continue
                # if usre input valid
                elif match:

                    # Utility object instantiated
                    utility = Utility()
                    # string -> datetime object
                    str2date = utility.str2date(date)
                    # Worklog object instantiated
                    search = Inspector()
                    # call to WorkLog.search_by_date mentod
                    # method handles search logic/ display of relevant entry
                    try:
                        clear()
                        "\n"
                        print('here are the matching entries: \n')
                        search_results = search.search_by_date(str2date)
                        app()
                    except ValueError:
                        print('It looks like there is no matching results')
                        app()

        # if duration prompt for duration get input
        elif search_option == 'b':
            # begin loop for entry search by duration data collection
            while True:

                duration = input('please input the duration of the task '
                                 'that you want to search: ')
                # tests input against  regex pattern
                durpattern = re.compile("(\d+)")
                durmatch = durpattern.fullmatch(duration)

                # if pattern fails test
                # messsage will prompt until correct format recieved
                if not durmatch:
                    print('this is not an appropriate format')
                    continue
                # if user input valid
                elif durmatch:
                    # Utility object instantiated
                    utility = Utility()
                    # string -> timedelta
                    str2time = utility.str2time(duration)
                    # Worklog object instantiated
                    search = Inspector()
                    # call to WorkLog.search_by_duration
                    # method handles search logic/ display of relevant entry
                    try:
                        clear()
                        "\n"
                        print('here are the matching entries: \n')
                        search_results = search.search_by_duration(str2time)
                        app()
                    except ValueError:
                        print('It looks like there is no matching results')
                        app()
        # if string  prompt for string get input
        elif search_option == 'c':
            while True:
                string = input('please type string and we'
                               'will search against it: ')
                # Worklog object instantiated
                search = Inspector()
                # call to WorkLog.search_by_duration
                # method handles search logic/ display of relevant entry
                try:
                    clear()
                    "\n"
                    print('here are the matching entries: ')
                    search_results = search.search_by_string(string)
                    # if now matching entries
                    app()
                except ValueError:
                    print('It looks like there is no matching results')
                    app()

        elif search_option == 'd':
            while True:
                string = input('please type employee name to search for: ')
                # Worklog object instantiated
                search = Inspector()
                # call to WorkLog.search_by_duration
                # method handles search logic/ display of relevant entry
                try:
                    clear()
                    "\n"
                    print('here are the matching entries: \n')
                    search_results = search.search_by_employee(string)
                    app()
                except ValueError:
                    print('It looks like there is no matching results')
                    app()
        elif search_option == 'e':
            clear()
            app()