[[TOC]]
This is a python sample for AlphaFlash select.
This was written using python 3.8.
The code can be run with
python selectsample.py xxx yyy
Where xxx is your username and yyy is your password. This will use the included simple STOMP implementation to connect.
Using the stomp.py library
This code also has a sample using the third party library stomp.py.
To use this this library, the stomp.py library will need to be installed on the host machine, either as a global python package, or using pipenv and the included Pipfile.
Once this is installed the stomp.py sample can be run by passing in an additional argument, "stomp.py", to the script.
Example running with pipenv:
pipenv run python selectsample.py xxx yyy stomp.py
Example running with stomp.py installed as a global package:
python selectsample.py xxx yyy stomp.py
selectsample.py demonstrates logging in and interacting with REST apis.
stompclient.py provides a basic stomp client for connectig to our real-time data service. This is intended as a demonstration and should not be used in production as-is!
Using the authentication service to get a token
auth_response = requests.post(
"https://api.alphaflash.com/api/auth/alphaflash-client/token",
json = { 'username':username, 'password':password }
)
if auth_response.status_code != 200:
print("Login failed")
exit(1)Getting calendar data
calendar_data = requests.get(
"https://api.alphaflash.com/api/select/calendar/events",
headers = {"Authorization": "Bearer " + access_token}
)Making a STOMP connection with stomp.py
# TODO - replace this with your message handling code
listener = stomp.PrintingListener()
c = stomp.Connection([("select.alphaflash.com",61614)],use_ssl=True,heartbeats=(0,30000))
c.set_listener('my_listener',listener)
c.connect(passcode=access_token, wait=True)
c.subscribe("/topic/observations",1)