示例#1
0
def search_currency(item, currency_column, date_column):
    '''
    This function search value of currency by date
    '''
    currency = item [currency_column]
    date  = item[date_column].date()
    if currency == CURRENCY_ERROR:
        return 1
    if currency == MX_CURRENCY:
        return 1
    fxrio = Fixerio(base='MXN')
    try:
        histo_dict = fxrio.historical_rates(date)
    except :
        time.sleep(3)
        histo_dict = fxrio.historical_rates(date)
    return histo_dict['rates'][currency]
示例#2
0
def forex():
    forex = forex_table_generator()
    error = ''
    try:
        forex = forex_table_generator()
        if request.method == "POST":
            forex = forex_table_generator()
            start_date = date(2018, 2, 25)
            end_date = date(2018, 4, 1)
            values = []
            dates = []
            line1 = []
            line2 = []
            a = request.form['cur1'].strip()
            b = request.form['cur2'].strip()
            base = request.form['base'].strip()
            datelist = pd.date_range(start_date, end_date).to_pydatetime()
            datelist.tolist()
            for dt in datelist:
                dates.append(dt.strftime("%Y-%m-%d"))
            fxrio = Fixerio()
            for d in dates:
                values.append(
                    fxrio.historical_rates(base=base, date=d, symbols=[a, b]))
            for i in range(len(values)):
                line1.append(values[i]['rates'][a])
                line2.append(values[i]['rates'][b])
            line_chart = pygal.Line(x_label_rotation=30)
            line_chart.title = a + ' vs ' + b + ' with base as ' + base
            line_chart.x_labels = map(str, dates)
            line_chart.add(a, line1)
            line_chart.add(b, line2)
            graph_data = line_chart.render_data_uri()
            return render_template('forex.html',
                                   graph_data=graph_data,
                                   forex=forex)

        else:
            error = 'Invalid Data'

        return render_template('forex.html', forex=forex)

    except Exception as e:
        flash(e)
        return render_template('forex.html', error=error)
def get_currency(currency, rate_in, date):
    fxrio = Fixerio(base=currency, symbols=rate_in, secure=True)
    return fxrio.historical_rates(date)