Ejemplo n.º 1
0
 def __init__(self, target_currency, api_key):
     """Initialize the data object."""
     self.api_key = api_key
     self.rate = None
     self.target_currency = target_currency
     self.exchange = Fixerio(symbols=[self.target_currency],
                             access_key=self.api_key)
Ejemplo n.º 2
0
def currencies(wrapper_kwargs, scraper):

    # Get data
    f = Fixerio(base='USD')
    upd = {'meta': {'currencies': f.latest().get('rates')}}

    # Save data
    return upd
Ejemplo n.º 3
0
 def __init__(self):  #, influxdb_client):
     self.fxrio = Fixerio()
     self.exchange_data = {}
     self._name = 'Exchange'
     self.baselist = {'CNY', 'USD', 'KRW'}
     self.exchange_data = {}
     for index in self.baselist:
         self.exchange_data[index] = None
     logger.info('Exchange module init')
Ejemplo n.º 4
0
    def __init__(self, base_currency, target_currency):
        """Initialize the data object."""
        from fixerio import Fixerio

        self.rate = None
        self.base_currency = base_currency
        self.target_currency = target_currency
        self.exchange = Fixerio(base=self.base_currency,
                                symbols=[self.target_currency],
                                secure=True)
Ejemplo n.º 5
0
 def __init__(self):  #, influxdb_client):
     self.fxrio = Fixerio()
     self.exchange_data = {}
     #self.client=influxdb_client
     #self._request_timeout = int(config.REQUEST_TIMEOUT)
     #self._price = 0.0
     self._name = 'Exchange'
     self.baselist = {'CNY', 'USD', 'KRW'}
     self.exchange_data = {}
     for index in self.baselist:
         self.exchange_data[index] = None
Ejemplo n.º 6
0
class Exchange(object):
    def __init__(self):  #, influxdb_client):
        self.fxrio = Fixerio()
        self.exchange_data = {}
        #self.client=influxdb_client
        #self._request_timeout = int(config.REQUEST_TIMEOUT)
        #self._price = 0.0
        self._name = 'Exchange'
        self.baselist = {'CNY', 'USD', 'KRW'}
        self.exchange_data = {}
        for index in self.baselist:
            self.exchange_data[index] = None

    @property
    def name(self):
        return self._name

    def query(self, callback_func=None):
        for index in self.baselist:
            res = self.fxrio.latest(base=index)
            self.parse_exchange(index, res)
        print(self.exchange_data)
        if callback_func is not None:
            callback_func(self.exchange_data)

    def parse_exchange(self, base, data):
        #data = json.loads(jsondata)
        data_dict = {}
        for key in data['rates']:
            if key in self.baselist:
                data_dict[key] = data['rates'][key]
        self.exchange_data[base] = data_dict
Ejemplo n.º 7
0
class Exchange(object):
    def __init__(self):  #, influxdb_client):
        self.fxrio = Fixerio()
        self.exchange_data = {}
        self._name = 'Exchange'
        self.baselist = {'CNY', 'USD', 'KRW'}
        self.exchange_data = {}
        for index in self.baselist:
            self.exchange_data[index] = None
        logger.info('Exchange module init')

    @property
    def name(self):
        return self._name

    def query(self, callback_func=None):
        for index in self.baselist:
            res = self.fxrio.latest(base=index)
            self.parse_exchange(index, res)
        if callback_func is not None:
            callback_func(self.exchange_data)

    def parse_exchange(self, base, data):
        #data = json.loads(jsondata)
        data_dict = {}
        for key in data['rates']:
            if key in self.baselist:
                data_dict[key] = data['rates'][key]
        self.exchange_data[base] = data_dict
Ejemplo n.º 8
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]
Ejemplo n.º 9
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)
Ejemplo n.º 10
0
    def __init__(self, target_currency, api_key):
        """Initialize the data object."""
        from fixerio import Fixerio

        self.api_key = api_key
        self.rate = None
        self.target_currency = target_currency
        self.exchange = Fixerio(
            symbols=[self.target_currency], access_key=self.api_key)
Ejemplo n.º 11
0
    def __init__(self, base_currency, target_currency):
        """Initialize the data object."""
        from fixerio import Fixerio

        self.rate = None
        self.base_currency = base_currency
        self.target_currency = target_currency
        self.exchange = Fixerio(
            base=self.base_currency, symbols=[self.target_currency],
            secure=True)
Ejemplo n.º 12
0
class ExchangeData:
    """Get the latest data and update the states."""
    def __init__(self, target_currency, api_key):
        """Initialize the data object."""
        self.api_key = api_key
        self.rate = None
        self.target_currency = target_currency
        self.exchange = Fixerio(symbols=[self.target_currency],
                                access_key=self.api_key)

    def update(self):
        """Get the latest data from Fixer.io."""
        self.rate = self.exchange.latest()
Ejemplo n.º 13
0
def convert_currency(base, to, amount):
    """Convert between two cryptocurrencies.

    base     str: code of base currency have to be supported by bitstamp (btc, ltc, xrp).
    to       str: code of currency into which we want to exchange have to be supported by
                  bitstamp (usd, eur) or Europen Bank
    amount float: The amount of money
    """
    assert base.lower() in ["ltc", "btc", "xrp"]

    if base.lower() in ["ltc", "xrp"] and to.lower() == "btc":
        rate = float(json.loads(requests.get(BITSTAMP_TICKER_BASE_URL.format(
                base=base.lower(), to=to.lower())).text)['last'])
    elif to.lower() not in ["usd", "eur"]:  # to currency is not supported by bitstamp
        response = json.loads(requests.get(BITSTAMP_TICKER_BASE_URL.format(
            base=base.lower(), to="usd")).text)
        fixerio = Fixerio(base="USD")  # HAVE TO BE ON SEPERATE LINE
        rate = fixerio.latest()["rates"][to.upper()] * float(response["last"])
    else:
        rate = float(json.loads(requests.get(BITSTAMP_TICKER_BASE_URL.format(
                base=base.lower(), to=to.lower())).text)["last"])

    return amount * rate
Ejemplo n.º 14
0
def setup_platform(hass, config, add_entities, discovery_info=None):
    """Set up the Fixer.io sensor."""
    api_key = config.get(CONF_API_KEY)
    name = config.get(CONF_NAME)
    target = config.get(CONF_TARGET)

    try:
        Fixerio(symbols=[target], access_key=api_key).latest()
    except FixerioException:
        _LOGGER.error("One of the given currencies is not supported")
        return

    data = ExchangeData(target, api_key)
    add_entities([ExchangeRateSensor(data, name, target)], True)
Ejemplo n.º 15
0
def setup_platform(hass, config, add_devices, discovery_info=None):
    """Setup the Fixer.io sensor."""
    from fixerio import (Fixerio, exceptions)

    name = config.get(CONF_NAME)
    base = config.get(CONF_BASE)
    target = config.get(CONF_TARGET)

    try:
        Fixerio(base=base, symbols=[target], secure=True).latest()
    except exceptions.FixerioException:
        _LOGGER.error('One of the given currencies is not supported')
        return False

    data = ExchangeData(base, target)
    add_devices([ExchangeRateSensor(data, name, target)])
Ejemplo n.º 16
0
class ExchangeData:
    """Get the latest data and update the states."""

    def __init__(self, target_currency, api_key):
        """Initialize the data object."""
        from fixerio import Fixerio

        self.api_key = api_key
        self.rate = None
        self.target_currency = target_currency
        self.exchange = Fixerio(
            symbols=[self.target_currency], access_key=self.api_key)

    def update(self):
        """Get the latest data from Fixer.io."""
        self.rate = self.exchange.latest()
Ejemplo n.º 17
0
class ExchangeData(object):
    """Get the latest data and update the states."""
    def __init__(self, base_currency, target_currency):
        """Initialize the data object."""
        from fixerio import Fixerio

        self.rate = None
        self.base_currency = base_currency
        self.target_currency = target_currency
        self.exchange = Fixerio(base=self.base_currency,
                                symbols=[self.target_currency],
                                secure=True)

    def update(self):
        """Get the latest data from Fixer.io."""
        self.rate = self.exchange.latest()
Ejemplo n.º 18
0
class ExchangeData(object):
    """Get the latest data and update the states."""

    def __init__(self, base_currency, target_currency):
        """Initialize the data object."""
        from fixerio import Fixerio

        self.rate = None
        self.base_currency = base_currency
        self.target_currency = target_currency
        self.exchange = Fixerio(
            base=self.base_currency, symbols=[self.target_currency],
            secure=True)

    def update(self):
        """Get the latest data from Fixer.io."""
        self.rate = self.exchange.latest()
Ejemplo n.º 19
0
def setup_platform(
    hass: HomeAssistant,
    config: ConfigType,
    add_entities: AddEntitiesCallback,
    discovery_info: DiscoveryInfoType | None = None,
) -> None:
    """Set up the Fixer.io sensor."""
    api_key = config.get(CONF_API_KEY)
    name = config.get(CONF_NAME)
    target = config.get(CONF_TARGET)

    try:
        Fixerio(symbols=[target], access_key=api_key).latest()
    except FixerioException:
        _LOGGER.error("One of the given currencies is not supported")
        return

    data = ExchangeData(target, api_key)
    add_entities([ExchangeRateSensor(data, name, target)], True)
 def __init__(self, access_key, fake_fixerio=None):
     self.fixerio = fake_fixerio or Fixerio(access_key=access_key)
Ejemplo n.º 21
0
import math
import re

from fixerio import Fixerio
from measurement.measures import Volume

fxrio = Fixerio(base='USD')
conversion = fxrio.latest()


def my_va_transform(s):
    """Function to transform brand
    * make lower
    * do specific regex replacements
    * remove product types ex: 'bourbon', 'whiskey'
    * sort the words in the brand
    """
    s = s.lower()

    replacements = {
        "^gentleman jack whiskey$": "jack daniel's gentleman jack",
        "^pritchard": "prichard",
        "^balcones baby blue corn whiskey$": "balcones baby blue",
        "^canadian club rye whisky$": "canadian club",
        "^catoctin creek roundstone rye whisky$":
        "catoctin creek roundstone rye",
        "^e h taylor jr. straight rye$": "colonel e.h. taylor straight rye",
        "^e h taylor seasoned wood$": "colonel e.h. taylor seasoned wood",
        "^james e. pepper 1776 rye": "james e. pepper 1776 straight rye",
        "^lock stock & barrel 16 yr straight rye whiskey$":
        "lock stock and barrel 16 straight rye",
Ejemplo n.º 22
0
from fixerio import Fixerio
import pandas as pd

fxrio = Fixerio(access_key='3401cd052e4ac3a55a8a9ea215b1ea8d')
ok = fxrio.latest()
currency = pd.DataFrame(ok)
currency.to_csv('currency.csv')
def get_currency(currency, rate_in, date):
    fxrio = Fixerio(base=currency, symbols=rate_in, secure=True)
    return fxrio.historical_rates(date)
Ejemplo n.º 24
0
def get_usd_inr():
    current = Fixerio(base='USD', symbols=['USD', 'INR'])
    return current.latest()
Ejemplo n.º 25
0
    'GNF', 'GTQ', 'GYD', 'HKD', 'HNL', 'HRK', 'HTG', 'HUF', 'IDR', 'ILS',
    'INR', 'IQD', 'IRR', 'ISK', 'JEP', 'JMD', 'JOD', 'JPY', 'KES', 'KGS',
    'KHR', 'KMF', 'KPW', 'KRW', 'KWD', 'KYD', 'KZT', 'LAK', 'LBP', 'LKR',
    'LRD', 'LSL', 'LTL', 'LVL', 'LYD', 'MAD', 'MDL', 'MGA', 'MKD', 'MMK',
    'MNT', 'MOP', 'MRO', 'MUR', 'MVR', 'MWK', 'MXN', 'MYR', 'MZN', 'NAD',
    'NGN', 'NIO', 'NOK', 'NPR', 'NZD', 'OMR', 'PAB', 'PEN', 'PGK', 'PHP',
    'PKR', 'PLN', 'PYG', 'QAR', 'RON', 'RSD', 'RUB', 'RWF', 'SAR', 'SBD',
    'SCR', 'SDG', 'SEK', 'SGD', 'SHP', 'SLL', 'SOS', 'SRD', 'STD', 'SVC',
    'SYP', 'SZL', 'THB', 'TJS', 'TMT', 'TND', 'TOP', 'TRY', 'TTD', 'TWD',
    'TZS', 'UAH', 'UGX', 'USD', 'UYU', 'UZS', 'VEF', 'VND', 'VUV', 'WST',
    'XAF', 'XCD', 'XDR', 'XOF', 'XPF', 'YER', 'ZAR', 'ZMK', 'ZWL'
]
convertFrom = str(sys.argv[1])
ConvertTo = 'EGP'
if convertFrom in symbols:
    fxrio = Fixerio(access_key='4901a054956048d6cdbd8a55db64709b')
    Rates = fxrio.latest(symbols=[
        ConvertTo, convertFrom
    ])  #the function always returns decitonry #the base always EUR
    isConvertedTo_Rate = Rates['rates'][ConvertTo]
    ConvertedFrom_Rate = Rates['rates'][convertFrom]
    CovertedFrom_Rate_referedToBase = 1 / ConvertedFrom_Rate
    finalRate = CovertedFrom_Rate_referedToBase * isConvertedTo_Rate
    print("1 " + convertFrom + " = " + str(finalRate) + " " + ConvertTo)
    #Update the DB
    sql = "INSERT INTO RATES(rate) VALUES (%f) WHERE currency='%s'" % (
        finalRate, convertFrom)
    cur.execute(sql)
else:
    print("Wrong currency symbol!!")