diff --git a/.gitignore b/.gitignore index ea06d6a..7305673 100644 --- a/.gitignore +++ b/.gitignore @@ -128,4 +128,6 @@ dmypy.json # Pyre type checker .pyre/ .DS_Store -**/*api_key* \ No newline at end of file +**/*api_key* +**/venv +**/tmp diff --git a/docs/flask.html b/docs/flask.html index 58e5d67..f132445 100644 --- a/docs/flask.html +++ b/docs/flask.html @@ -139,6 +139,7 @@

Flask

+

Simple Example

PyVibe can be used with Flask. This is a simple example of how to use PyVibe with Flask.

First, create a new file called app.py and add the following code:

@@ -179,6 +180,24 @@ python app.py
+ +

Extended Example

+PyPi Analytics +

+ + Live App + + +

+

+ + Source Code on GitHub + + +

+ + + + """ + +class WebSocketSenderComponent(pv.Component): + def __init__(self, path_to_websocket: str): + self.path_to_websocket = path_to_websocket + + def to_html(self): + return """ +
+
+ + +
+ +
+ + """ + +@app.route('/') +def index(): + page = pv.Page('Websocket Test', description='WebSocket proof of concept using Flask-Sock and PyVibe') + + page.add_header("Websocket Test") + + with page.add_container(grid_columns=2) as container: + with container.add_card() as card: + card.add_header('Send') + card.add_component(WebSocketSenderComponent('/echo')) + + with container.add_card() as card: + card.add_header('Receive') + card.add_component(WebSocketReceiverComponent('/echo')) + + page.add_header("Source Code") + page.add_emgithub("https://github.com/pycob/pyvibe/blob/main/sample-apps/websockets/main.py") + + return page.to_html() + +from threading import Timer + +@sock.route('/echo') +def echo(sock): + while True: + data = sock.receive() + + alert_component = pv.AlertComponent(data, 'Received') + + sock.send(alert_component.to_html()) + +if __name__ == '__main__': + app.run(debug=True) \ No newline at end of file diff --git a/sample-apps/websockets/requirements.txt b/sample-apps/websockets/requirements.txt new file mode 100644 index 0000000..565943a --- /dev/null +++ b/sample-apps/websockets/requirements.txt @@ -0,0 +1,5 @@ +pyvibe +pycob +flask +flask-sock +gunicorn