|
@ -1,8 +1,11 @@ |
|
|
|
|
|
# Centrifugo Test |
|
|
|
|
|
|
|
|
from flask import Flask, redirect |
|
|
from flask import Flask, redirect |
|
|
from donationalerts_api import DonationAlertsApi, Centrifugo, Scopes, Channels |
|
|
from donationalerts_api import DonationAlertsApi, Centrifugo, Scopes, Channels |
|
|
|
|
|
|
|
|
app = Flask(__name__) |
|
|
app = Flask(__name__) |
|
|
api = DonationAlertsApi("client id", "client secret", "http://127.0.0.1:5000/login", Scopes.ALL_SCOPES) |
|
|
api = DonationAlertsApi("client id", "client secret", "http://127.0.0.1:5000/login", |
|
|
|
|
|
[Scopes.USER_SHOW, Scopes.DONATION_SUBSCRIBE]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.route("/", methods=["get"]) |
|
|
@app.route("/", methods=["get"]) |
|
@ -12,19 +15,19 @@ def index(): |
|
|
|
|
|
|
|
|
@app.route("/login", methods=["get"]) |
|
|
@app.route("/login", methods=["get"]) |
|
|
def login(): |
|
|
def login(): |
|
|
"""Beta ~""" |
|
|
|
|
|
|
|
|
|
|
|
code = api.get_code() |
|
|
code = api.get_code() |
|
|
|
|
|
|
|
|
access_token = api.get_access_token(code) |
|
|
access_token = api.get_access_token(code) |
|
|
socket_token = api.get_user(access_token)["data"]["socket_connection_token"] |
|
|
|
|
|
user_id = api.get_user(access_token)["data"]["id"] |
|
|
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 = Centrifugo(socket_token, access_token, user_id) |
|
|
fugo.connect() |
|
|
fugo.connect() |
|
|
|
|
|
fugo.subscribe(Channels.NEW_DONATION_ALERTS) |
|
|
|
|
|
|
|
|
return fugo.subscribe([Channels.NEW_DONATION_ALERTS]) |
|
|
event = fugo.listen() |
|
|
|
|
|
return event |
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
if __name__ == "__main__": |
|
|
app.run(debug=True) |
|
|
app.run(debug=True) |