From 36df1265db00c7993f41a5ca7f1d701142f14976 Mon Sep 17 00:00:00 2001 From: Fsoky Date: Tue, 10 Aug 2021 16:37:13 +0600 Subject: [PATCH] Example --- test.py | 36 +++++------------------------------- 1 file changed, 5 insertions(+), 31 deletions(-) diff --git a/test.py b/test.py index 43dbe48..e53ecda 100644 --- a/test.py +++ b/test.py @@ -1,33 +1,7 @@ -# Centrifugo Test +from donationalerts_api import Alert -from flask import Flask, redirect -from donationalerts_api import DonationAlertsApi, Centrifugo, Scopes, Channels +alert = Alert("token") -app = Flask(__name__) -api = DonationAlertsApi("client id", "client secret", "http://127.0.0.1:5000/login", - [Scopes.USER_SHOW, Scopes.DONATION_SUBSCRIBE]) - - -@app.route("/", methods=["get"]) -def index(): - return redirect(api.login()) - - -@app.route("/login", methods=["get"]) -def login(): - code = api.get_code() - access_token = api.get_access_token(code) - - user = api.get_user(access_token) - socket_token = user["socket_connection_token"] - user_id = user["id"] - - fugo = Centrifugo(socket_token, access_token, user_id) - fugo.connect() - fugo.subscribe(Channels.NEW_DONATION_ALERTS) - - event = fugo.listen() - return event - -if __name__ == "__main__": - app.run(debug=True) \ No newline at end of file +@alert.event() +def new_donation(event): + print(event) \ No newline at end of file