Examples

This is a collection of examples that show how to use the library. It does not cover every function, but it does cover the most common ones. The PyForks tests (PyForks/_test/*.py) can also provide you with details on how to use each function. The examples are broken down into three classes:

  • Regions - Trailforks regions.

  • Trails - Trailforks region trails.

  • Events - Events for a region/area.

Regions

Regions for Trailforks can have several layers. It’s best to think of them as a tree even though all of them are “Regions”. For example, Minnesota (region id: 3203) is a region, but so are the many different bike parks/trails within Minnesota, such as Lebanon Hills (region id: 3438). There is a geographic hierarchy, but it really does not matter for the API as a region is simply a region as long as it has a region id.

Get Region Information

1from PyForks import Regions
2
3region_api = Regions(app_id='your_app_id', app_secret='your_app_secret')
4params = {'filter': 'rid::12345'}
5region_api.get_region(**params)

Get Region Status

 1from PyForks import Regions
 2from PyForks.lookups import trail_status_short
 3from datetime import datetime
 4import time
 5
 6regions = Regions(app_id=app_id, app_secret=app_secret)             # Create a new instance of the Regions class
 7
 8date_obj = datetime.strptime("2022-01-01", "%Y-%m-%d")              # Create a datetime object
 9since_timestamp = int(time.mktime(date_obj.timetuple()))            # Convert the datetime object to a timestamp
10args = {"rids": west_lake_marion_id}                                # Create a dictionary of arguments to pass to the get_region_status method
11
12region_status = regions.get_region_status(since_timestamp, **args)
13# Columns: id,status,condition,status_ts,last_report_ts,changed
14columns = region_status.get("data", {}).get("updates", {}).get("regions_info", {}).get("columns", [])
15rows = region_status.get("data", {}).get("updates", {}).get("regions_info", {}).get("rows", [])
16
17for row in rows:
18    print(trail_status_short.get(row[1]))
19    print(trail_status.get(row[1]))

Trails

Get Trails by Region

1from PyForks import Trails
2
3trail_api = Trails(app_id='your_app_id', app_secret='your_app_secret')
4args = {"filter": "rid::20367"} # Minnesota Region
5trail_api.get_trails(**args) # Get all trails for the Minnesota region

Get Trail Information

1from PyForks import Trails
2
3trail_api = Trails(app_id='your_app_id', app_secret='your_app_secret')
4trail_id = 12345
5trail_api.get_trail(trail_id)

Get Trail Status

1from PyForks import Trails
2from PyForks.lookups import trail_status_short
3
4trail_api = Trails(app_id='your_app_id', app_secret='your_app_secret')
5trail_id = 12345
6trail_status = trail_api.get_trail_status(trail_id)
7status_int = response.get("data", {}).get("updates", {}).get("trails_info", {}).get("rows", [[]])[0][1]
8print(trail_status_short.get(status_int))

Events

Get Events by Region

1from PyForks import Events
2
3event_api = Events(app_id='your_app_id', app_secret='your_app_secret')
4args = {"filter": "rid::3203"} # Minnesota Region
5event_api.get_events(**args) # Get all events for the Minnesota region

Get Event Information

1from PyForks import Events
2
3event_api = Events(app_id='your_app_id', app_secret='your_app_secret')
4event_id = 12345
5event_api.get_event(event_id)