Skip to content

Python client for interacting with the Trace Action Sports Tracker API

License

Notifications You must be signed in to change notification settings

aiguofer/py-trace

Repository files navigation

Trace Python Client

Documentation Status

Python client for interacting with the Trace api. For information on the API see the api documentation

Getting Started

To use in REPL or a non-GUI app:

from py_trace import Trace

client = Trace(<client_key>, <client_secret>)
client.get_authorization_url()
# output should be like https://www.alpinereplay.com/api/oauth_login?oauth_token=<token>, go to the url and authorize the app
# after authorization, you should see a url like http://snow.traceup.com/api/oauth_login?oauth_token=<token>&oauth_verifier=<verifier>
client.get_access_token(<verifier>)
client.get_user()

To use in a web app (using a very basic Flask example):

from flask import Flask, request, redirect
import json

app = Flask(__name__)
trace = Trace(<client_key>, <client_secret>, 'http://127.0.0.1:5000/auth_callback')

@app.route('/auth_callback')
def handle_redirect():
    trace.get_access_token(request.args['oauth_verifier'])
    return redirect('/user')

@app.route('/auth')
def get_user_token():
    url = trace.get_auth_url()
    return redirect(url)

@app.route('/user')
def get_user():
    return json.dumps(trace.get_user())

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.