1 changed files with 5 additions and 31 deletions
@ -1,33 +1,7 @@ |
|||||
# Centrifugo Test |
from donationalerts_api import Alert |
||||
|
|
||||
from flask import Flask, redirect |
alert = Alert("token") |
||||
from donationalerts_api import DonationAlertsApi, Centrifugo, Scopes, Channels |
|
||||
|
|
||||
app = Flask(__name__) |
@alert.event() |
||||
api = DonationAlertsApi("client id", "client secret", "http://127.0.0.1:5000/login", |
def new_donation(event): |
||||
[Scopes.USER_SHOW, Scopes.DONATION_SUBSCRIBE]) |
print(event) |
||||
|
|
||||
|
|
||||
@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) |
|
Loading…
Reference in new issue