Skip to content

mni-news/af-select-sample-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AlphaFlash Select Python Samples

[[TOC]]

This is a python sample for AlphaFlash select.

This was written using python 3.8.

Running the code

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

About the code

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!

Some useful snippets

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)

About

Python sample for AlphaFlash select

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages