def index():
    ds = DataSource('hayesrichn', 'orange227blue')

    today = ds.dateTimeToStr(datetime.datetime.today().date())
    today = ds.strToInt(today)
    # If the tables were constantly updated from yahooFiance. Because our tables are
    # not constantly updated. We will have place holder to have the most recent price

    today = 20191008

    returndata = ds.performDataQuery(['spy', 'btc', 'gld', 'irx'],
                                     'adjcloseprice', today - 1, today)
    returndata = ds.formatData(returndata)
    listOfreturnHTML = makePriceChangeBetweenTwoDaysHTML(returndata)

    return render_template('index.html', listOfreturnHTML=listOfreturnHTML)
def result():
    if request.method == 'POST':
        ds = DataSource('hayesrichn', 'orange227blue')
        date1 = ds.strToInt(request.form.get('date1'))
        date2 = ds.strToInt(request.form.get('date2'))
        datatype = request.form.get('datatype')
        dataset1 = request.form.get('dataset1')
        dataset2 = request.form.get('dataset2')
        returndata = ds.performDataQuery([dataset1, dataset2], datatype, date1,
                                         date2)

        returnhtml = "<h2>DATA</h2>"
        returndata = ds.formatData(returndata)
        if returndata == []:
            returnhtml = "<h2>Query Failed</h2>"

        returnhtml = flask.Markup(returnhtml)

        dataset1ValueList = []
        dataset2ValueList = []
        datesValueList = []
        for tupleIndex in range(len(returndata)):
            if returndata[tupleIndex][1] != "No Data" and returndata[
                    tupleIndex][2] != "No Data":
                dataset1ValueList.append(returndata[tupleIndex][1])
                dataset2ValueList.append(returndata[tupleIndex][2])
                datesValueList.append(returndata[tupleIndex][0])

        plt.figure()
        fig, ax1 = plt.subplots()
        color = 'tab:red'
        ax1.set_xlabel('Dates')
        ax1.set_ylabel(str(dataset1) + " " + str(datatype), color=color)
        ax1.scatter(datesValueList, dataset1ValueList, color=color)

        ax1.tick_params(axis='y', labelcolor=color)

        ax2 = ax1.twinx(
        )  # instantiate a second axes that shares the same x-axis
        color = 'tab:blue'
        ax2.set_ylabel(str(dataset2) + " " + str(datatype),
                       color=color)  # we already handled the x-label with ax1
        ax2.scatter(datesValueList, dataset2ValueList, color=color)
        ax2.tick_params(axis='y', labelcolor=color)

        xticks = ax1.get_xticks()
        plt.xticks([xticks[0], xticks[-1]], visible=True, rotation="vertical")

        fig.tight_layout()

        image = BytesIO()
        plt.savefig(image, format='png')
        image.seek(0)

        return render_template('results.html',
                               returnhtml=returnhtml,
                               returndata=reversed(returndata),
                               dataset1=dataset1,
                               dataset2=dataset2,
                               datatype=datatype,
                               image=base64.b64encode(
                                   image.read()).decode('utf8'))
    else:
        returnhtml = "<h2>Query Failed</h2>"
        returnhtml = flask.Markup(returnhtml)
        return render_template('results.html', returnhtml=returnhtml)