Welcome to Trace Python Client’s documentation!¶
Trace Python Client¶
Python client for interacting with the Trace api. For information on the API see the api documentation
- Free software: MIT license
- Documentation: https://py-trace.readthedocs.io.
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.
Installation¶
Stable release¶
To install Trace Python Client, run this command in your terminal:
$ pip install py_trace
This is the preferred method to install Trace Python Client, as it will always install the most recent stable release.
If you don’t have pip installed, this Python installation guide can guide you through the process.
From sources¶
The sources for Trace Python Client can be downloaded from the Github repo.
You can either clone the public repository:
$ git clone git://github.com/aiguofer/py-trace
Or download the tarball:
$ curl -OL https://github.com/aiguofer/py-trace/tarball/master
Once you have a copy of the source, you can install it with:
$ python setup.py install
Modules¶
py_trace package¶
Module contents¶
Top-level package for Trace Python Client.
-
class
py_trace.
Trace
(client_key, client_secret, callback_uri=None, access_token=None, sport='snow')[source]¶ -
api_request
(path, method='GET', **kwargs)[source]¶ Make a request to the API and parse the results
Parameters: - path (str) – API endpoint to hit, must start with /
- method (str) – HTTP method (Default value = ‘GET’)
- **kwargs –
Arguments to pass to the request, see
requests.request
-
authenticate
(access_token)[source]¶ Step 4 of auth, authenticate the user by creating a session with the access token. This is optional as it is called by get_access_token. If you already have the access_token, you can call this function directly or pass the access_token when instanciating the class in order to authenticate.
Parameters: access_token (dict) – A dict containing the oauth_token and oauth_token_secret.
-
create_event_comment
(event_id, message)[source]¶ Add a comment to an event
Parameters: - event_id (int,str) – Event ID
- message (str) – Comment text
-
create_visit_comment
(visit_id, facebook=False, twitter=False, photo=None, hide_resort_name=0, comment=None, equipment=None)[source]¶ Add comment to a visit
Parameters: - visit_id (int,str) – Visit ID
- facebook (bool) – Whether to post to facebook or not (Default value = False)
- twitter (bool) – Whether to post to twitter or not (Default value = False)
- photo – (Default value = None)
- hide_resort_name – (Default value = 0)
- comment (str) – Comment text (Default value = None)
- equipment (list) – List of strings for each equipment item (Default value = None)
-
create_visit_equipment
(visit_id, equipment)[source]¶ Add equipment info for a visit
Parameters: - visit_id (int,str) – Visit ID
- equipment (list) – List of strings for each equipment item
-
create_visit_export
(visit_id)[source]¶ Create an export of the visit gpx file
Parameters: visit_id (int,str) – Visit ID
-
create_visit_photo
(visit_id, photo)[source]¶ Add a photo to a visit
Parameters: - visit_id (int,str) – Visit ID
- photo –
-
get_access_token
(oauth_verifier)[source]¶ Step 3 of auth, get the access token. After the user authorizes the app, we get the access token using the oauth_verifier and then authenticate the user.
Parameters: oauth_verifier (str) – A string containing the verifier
Step 2 of auth, get the authorization URL. It will first get the request token if it needs it.
-
get_events
(min_timestamp=None, max_timestamp=None, limit=None, ffilter=None)[source]¶ Get all events for yourself
Parameters: - min_timestamp (int) – Minimum timestamp to filter results (Default value = None)
- max_timestamp (int) – Maximum timestamp to filter results (Default value = None)
- limit (str,int) – Limit the number of entries in responses, if None is given the API defaults to 50 (Default value = None)
- ffilter (dict) – A filter for fields to be returned, see documentation for more (Default value = None)
-
get_request_token
()[source]¶ Step 1 of auth, get the request token. This is optional as this is called by get_auth_url if needed.
-
get_user
(user_id='self')[source]¶ Get user info
Parameters: user_id (int,str) – User ID (Default value = ‘self’)
-
get_visit_equipment
(visit_id)[source]¶ Get equipment info for a visit
Parameters: visit_id (int,str) – Visit ID
-
get_visit_events
(visit_id, ffilter=None)[source]¶ Get all events for a visit
Parameters: - visit_id (int,str) – Visit ID
- ffilter (dict) –
A filter for fields to be returned, see documentation for more (Default value = None)
-
get_visit_list
(user_id='self', ffilter=None)[source]¶ Get list of user visits
Parameters: - user_id (int,str) – User ID (Default value = ‘self’)
- ffilter (dict) –
A filter for fields to be returned, see documentation for more (Default value = None)
-
get_visit_weather
(visit_id)[source]¶ Get weather report for visit if available
Parameters: visit_id (int,str) – Visit ID
-
get_visits
(user_id='self', limit=None, min_timestamp=None, max_timestamp=None, visit_ids=None, ffilter=None)[source]¶ Get all user visits
Parameters: - user_id (int,str) – User ID (Default value = ‘self’)
- limit (str,int) – Limit the number of entries in responses, if None is given the API defaults to 50 (Default value = None)
- min_timestamp (int) – Minimum timestamp to filter results (Default value = None)
- max_timestamp (int) – Maximum timestamp to filter results (Default value = None)
- visit_ids (list) – List of visit IDs to include (Default value = None)
- ffilter (dict) –
A filter for fields to be returned, see documentation for more (Default value = None)
Share a visit
Parameters: - visit_id (int,str) – Visit ID
- stats (list) – List of stats to include, one of [total_distance, jumps, air_time, avg_speed, calories, vertical_drop, sustained_speed, slope_time, max_slope, turns_num, longest_ride]
- comment (str) – Comment text (Default value = None)
- photo – (Default value = None)
- facebook (bool) – Whether to post to facebook or not (Default value = True)
- twitter (bool) – Whether to post to twitter or not (Default value = True)
-
Contributing¶
Contributions are welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given.
You can contribute in many ways:
Types of Contributions¶
Report Bugs¶
Report bugs at https://github.com/aiguofer/py-trace/issues.
If you are reporting a bug, please include:
- Your operating system name and version.
- Any details about your local setup that might be helpful in troubleshooting.
- Detailed steps to reproduce the bug.
Fix Bugs¶
Look through the GitHub issues for bugs. Anything tagged with “bug” and “help wanted” is open to whoever wants to implement it.
Implement Features¶
Look through the GitHub issues for features. Anything tagged with “enhancement” and “help wanted” is open to whoever wants to implement it.
Write Documentation¶
Trace Python Client could always use more documentation, whether as part of the official Trace Python Client docs, in docstrings, or even on the web in blog posts, articles, and such.
Submit Feedback¶
The best way to send feedback is to file an issue at https://github.com/aiguofer/py-trace/issues.
If you are proposing a feature:
- Explain in detail how it would work.
- Keep the scope as narrow as possible, to make it easier to implement.
- Remember that this is a volunteer-driven project, and that contributions are welcome :)
Get Started!¶
Ready to contribute? Here’s how to set up py-trace for local development.
Fork the py-trace repo on GitHub.
Clone your fork locally:
$ git clone git@github.com:aiguofer/py-trace.git
Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up your fork for local development:
$ mkvirtualenv py-trace $ cd py-trace/ $ python setup.py develop
Create a branch for local development:
$ git checkout -b name-of-your-bugfix-or-feature
Now you can make your changes locally.
When you’re done making changes, check that your changes pass flake8 and the tests, including testing other Python versions with tox:
$ flake8 py_trace tests $ python setup.py test or py.test $ tox
To get flake8 and tox, just pip install them into your virtualenv.
Commit your changes and push your branch to GitHub:
$ git add . $ git commit -m "Your detailed description of your changes." $ git push origin name-of-your-bugfix-or-feature
Submit a pull request through the GitHub website.
Pull Request Guidelines¶
Before you submit a pull request, check that it meets these guidelines:
- The pull request should include tests.
- If the pull request adds functionality, the docs should be updated. Put your new functionality into a function with a docstring, and add the feature to the list in README.rst.
- The pull request should work for Python 2.7, 3.4, 3.5 and 3.6, and for PyPy. Check https://travis-ci.org/aiguofer/py-trace/pull_requests and make sure that the tests pass for all supported Python versions.
Deploying¶
A reminder for the maintainers on how to deploy. Make sure all your changes are committed (including an entry in HISTORY.rst). Then run:
$ bumpversion patch # possible: major / minor / patch
$ git push
$ git push --tags
Travis will then deploy to PyPI if tests pass.
Credits¶
Development Lead¶
- Diego Fernandez <aiguo.fernandez@gmail.com>
Contributors¶
None yet. Why not be the first?