loadCurrencies.py 865 Bytes
Newer Older
1
from backend.models.currency import Currency
Florent Chehab's avatar
Florent Chehab committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
import os
import csv
from .loadGeneric import LoadGeneric
from decimal import Decimal


class LoadCurrencies(LoadGeneric):

    def __init__(self, admin):
        self.admin = admin

    def load(self):
        tmp = os.path.join(os.path.realpath(__file__),
                           '../../assets/currencies.csv')
        currencies_file_loc = os.path.abspath(tmp)

        with open(currencies_file_loc) as csvfile:
            reader = csv.reader(csvfile, quotechar='"')
            next(reader)
            for r in reader:
                currency = Currency(
                    code=r[0],
                    name=r[1],
                    symbol="",
                    one_EUR_in_this_currency=Decimal(r[2])
                )
                currency.save()
                self.add_info(currency, self.admin)