import csv
from datetime import datetime


def process_csv_file(fpath):
    """ Retrieves the date and closing stock price listed in the CSV
        file specified by fpath
        Inputs
        fpath - path to the input CSV file. The CSV file is assumed to contain
                a header line as well as having the first column as the Dates
                (day-Month-year) and the fifth column contains the closing
                price.

        Exceptions:
        ValueError - will be raised if the program fails to interpret a Date
        IOError - failure to open or read from the input file

        returns - A list of tuples consisting of the parsed dates (as datetime
                  objects)
                  and the closing price. The tuples are sorted by date.
    """
    with open(fpath, "r") as f:
        reader = csv.reader(f)
        data = [row for row in reader]
        data = data[1:] # skip over the header
        # get the date, closing price
        data = [(datetime.strptime(r[0], "%d-%b-%y"), float(r[4])) for r in data]

    # sort by date
    data = sorted(data, key=lambda x: x[0])
    return data