コード例 #1
0
ファイル: app.py プロジェクト: possiblecode/exchangeratesapi
from sanic import Sanic
from sanic.response import file, html, json, redirect

from exchangerates.utils import Gino, cors, parse_database_url

HISTORIC_RATES_URL = "https://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist.xml"
LAST_90_DAYS_RATES_URL = (
    "https://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist-90d.xml")

app = Sanic()
app.config.update(
    parse_database_url(
        url=getenv("DATABASE_URL", "postgresql://localhost/exchangerates")))

# Database
db = Gino(app)

# Sentry
sentry = Sentry(app)


class ExchangeRates(db.Model):
    __tablename__ = "exchange_rates"

    date = db.Column(db.Date(), primary_key=True)
    rates = db.Column(JSONB())

    def __repr__(self):
        return "Rates [{}]".format(self.date)

コード例 #2
0
HISTORIC_RATES_URL = "https://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist.xml"
LAST_90_DAYS_RATES_URL = (
    "https://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist-90d.xml"
)


app = Sanic(name='xchangeapi')
app.config.update(
    parse_database_url(
        url=getenv("DATABASE_URL")
    )
)

# Database
#app.config.DB_USE_CONNECTION_FOR_REQUEST = False
db = Gino()
db.init_app(app)

# Sentry
sentry = Sentry(app)


class ExchangeRates(db.Model):
    __tablename__ = "exchange_rates"

    date = db.Column(db.Date(), primary_key=True)
    rates = db.Column(JSONB())

    def __repr__(self):
        return "Rates [{}]".format(self.date)