Ejemplo n.º 1
0
def main():
    # Make sure Lightbus formats its logs correctly
    lightbus.configure_logging()

    # Create our lightbus client and our web application
    bus = lightbus.create()
    app = web.Application()

    app.router.add_route("GET", "/", home_view)
    app.on_startup.append(start_listener)
    app.on_cleanup.append(cleanup)

    # Store the bus on `app` as we'll need it
    # in start_listener() and cleanup()
    app.bus = bus

    web.run_app(app, host="127.0.0.1", port=5000)
Ejemplo n.º 2
0
"""A simple pet shop

Shows a list of animals, and you can click on each one.

Image resizing and page view tracking performed using lightbus.
"""
import lightbus
from flask import Flask

from lightbus_examples.ex03_worked_example.store.bus import bus

app = Flask(__name__)

lightbus.configure_logging()

PETS = (
    "http://store.company.com/image1.jpg",
    "http://store.company.com/image2.jpg",
    "http://store.company.com/image3.jpg",
)


@app.route("/")
def home():
    html = "<h1>Online pet store</h1><br>"

    for pet_num, image_url in enumerate(PETS):
        resized_url = bus.image.resize(url=image_url, width=200, height=200)
        html += f'<a href="/pet/{pet_num}">' f'<img src="{resized_url}">' f"</a> "

    bus.store.page_view.fire(url="/")
Ejemplo n.º 3
0
def setup_logging(override: str, config: Config):
    configure_logging(
        log_level=(override or config.bus().log_level.value).upper())