Jikkii commited on
Commit
b2ff92e
·
0 Parent(s):

Initial commit

Browse files
Files changed (5) hide show
  1. .gitignore +3 -0
  2. app.py +91 -0
  3. camptocamp_api.py +126 -0
  4. main.py +16 -0
  5. requirements.txt +2 -0
.gitignore ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ __pycache__
2
+ .env
3
+ .idea
app.py ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from camptocamp_api import CamptocampAPI
3
+ from typing import Tuple, Optional
4
+
5
+
6
+ # Instantiate API
7
+ c2c = CamptocampAPI(language="en")
8
+
9
+ def get_recent_outings(
10
+ west: float, south: float, east: float, north: float,
11
+ start_date: Optional[str], end_date: Optional[str],
12
+ activity: Optional[str], limit: int
13
+ ):
14
+ bbox = (west, south, east, north)
15
+ date_range = (start_date, end_date) if start_date and end_date else None
16
+ return c2c.get_recent_outings(bbox, date_range, activity, limit)
17
+
18
+ def search_routes_by_activity(
19
+ west: float, south: float, east: float, north: float,
20
+ activity: str, limit: int
21
+ ):
22
+ bbox = (west, south, east, north)
23
+ return c2c.search_routes_by_activity(bbox, activity, limit)
24
+
25
+ def get_route_details(route_id: int):
26
+ return c2c.get_route_details(route_id)
27
+
28
+ def search_waypoints(
29
+ west: float, south: float, east: float, north: float,
30
+ limit: int
31
+ ):
32
+ bbox = (west, south, east, north)
33
+ return c2c.search_waypoints(bbox, limit)
34
+
35
+
36
+ with gr.Blocks(title="Camptocamp API MCP") as demo:
37
+ gr.Markdown("# 🏔️ Camptocamp API Interface")
38
+
39
+ with gr.Tab("Recent Outings"):
40
+ with gr.Row():
41
+ west = gr.Number(label="West")
42
+ south = gr.Number(label="South")
43
+ east = gr.Number(label="East")
44
+ north = gr.Number(label="North")
45
+ with gr.Row():
46
+ start_date = gr.Textbox(label="Start Date (YYYY-MM-DD)")
47
+ end_date = gr.Textbox(label="End Date (YYYY-MM-DD)")
48
+ activity = gr.Textbox(label="Activity (e.g. hiking, skiing)")
49
+ limit = gr.Number(label="Limit", value=5)
50
+ outings_output = gr.JSON()
51
+ outings_btn = gr.Button("Get Outings")
52
+ outings_btn.click(get_recent_outings,
53
+ inputs=[west, south, east, north, start_date, end_date, activity, limit],
54
+ outputs=outings_output)
55
+
56
+ with gr.Tab("Routes"):
57
+ with gr.Row():
58
+ r_west = gr.Number(label="West")
59
+ r_south = gr.Number(label="South")
60
+ r_east = gr.Number(label="East")
61
+ r_north = gr.Number(label="North")
62
+ r_activity = gr.Textbox(label="Activity")
63
+ r_limit = gr.Number(label="Limit", value=5)
64
+ route_output = gr.JSON()
65
+ route_btn = gr.Button("Search Routes")
66
+ route_btn.click(search_routes_by_activity,
67
+ inputs=[r_west, r_south, r_east, r_north, r_activity, r_limit],
68
+ outputs=route_output)
69
+
70
+ with gr.Tab("Route Details"):
71
+ route_id_input = gr.Number(label="Route ID")
72
+ route_details_output = gr.JSON()
73
+ route_details_btn = gr.Button("Get Route Details")
74
+ route_details_btn.click(get_route_details,
75
+ inputs=[route_id_input],
76
+ outputs=route_details_output)
77
+
78
+ with gr.Tab("Waypoints"):
79
+ with gr.Row():
80
+ w_west = gr.Number(label="West")
81
+ w_south = gr.Number(label="South")
82
+ w_east = gr.Number(label="East")
83
+ w_north = gr.Number(label="North")
84
+ w_limit = gr.Number(label="Limit", value=5)
85
+ waypoints_output = gr.JSON()
86
+ waypoints_btn = gr.Button("Search Waypoints")
87
+ waypoints_btn.click(search_waypoints,
88
+ inputs=[w_west, w_south, w_east, w_north, w_limit],
89
+ outputs=waypoints_output)
90
+
91
+ demo.launch()
camptocamp_api.py ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ from typing import Tuple, Optional, Dict, Any
3
+
4
+
5
+ class CamptocampAPI:
6
+ """
7
+ A Python wrapper for the Camptocamp.org REST API v6.
8
+ Supports querying outings, routes, waypoints, and more.
9
+ """
10
+
11
+ BASE_URL = "https://api.camptocamp.org"
12
+
13
+ def __init__(self, language: str = "en") -> None:
14
+ """
15
+ Initialize the API client.
16
+
17
+ Args:
18
+ language (str): Language code for results ('en', 'fr', etc.).
19
+ """
20
+ self.language = language
21
+
22
+ def _request(self, endpoint: str, params: Dict[str, Any]) -> Dict[str, Any]:
23
+ """
24
+ Internal method to send a GET request to the Camptocamp API.
25
+
26
+ Args:
27
+ endpoint (str): API endpoint (e.g., "/outings").
28
+ params (Dict): Dictionary of query parameters.
29
+
30
+ Returns:
31
+ Dict: Parsed JSON response.
32
+ """
33
+ params["pl"] = self.language
34
+ url = f"{self.BASE_URL}{endpoint}"
35
+ response = requests.get(url, params=params)
36
+ response.raise_for_status()
37
+ return response.json()
38
+
39
+ def get_recent_outings(
40
+ self,
41
+ bbox: Tuple[float, float, float, float],
42
+ date_range: Optional[Tuple[str, str]] = None,
43
+ activity: Optional[str] = None,
44
+ limit: int = 10,
45
+ ) -> Dict[str, Any]:
46
+ """
47
+ Get recent outings around a specific location and date.
48
+
49
+ Args:
50
+ bbox (Tuple[float, float, float, float]): Bounding box as (west, south, east, north).
51
+ date_range (Optional[Tuple[str, str]]): Date range (start, end) in YYYY-MM-DD format.
52
+ activity (Optional[str]): Activity filter (e.g., "climbing", "hiking").
53
+ limit (int): Max number of results.
54
+
55
+ Returns:
56
+ Dict: API response containing outings.
57
+ """
58
+ params = {
59
+ "bbox": ",".join(map(str, bbox)),
60
+ "limit": limit,
61
+ "orderby": "-date",
62
+ }
63
+ if date_range:
64
+ params["date"] = f"{date_range[0]},{date_range[1]}"
65
+ if activity:
66
+ params["act"] = activity
67
+
68
+ return self._request("/outings", params)
69
+
70
+ def search_routes_by_activity(
71
+ self,
72
+ bbox: Tuple[float, float, float, float],
73
+ activity: str,
74
+ limit: int = 10,
75
+ ) -> Dict[str, Any]:
76
+ """
77
+ Search for routes in a given area and activity type.
78
+
79
+ Args:
80
+ bbox (Tuple[float, float, float, float]): Bounding box as (west, south, east, north).
81
+ activity (str): Activity filter (e.g., "rock_climbing").
82
+ limit (int): Max number of results.
83
+
84
+ Returns:
85
+ Dict: API response containing route data.
86
+ """
87
+ params = {
88
+ "bbox": ",".join(map(str, bbox)),
89
+ "act": activity,
90
+ "limit": limit,
91
+ "orderby": "-date",
92
+ }
93
+ return self._request("/routes", params)
94
+
95
+ def get_route_details(self, route_id: int) -> Dict[str, Any]:
96
+ """
97
+ Retrieve full route information by its ID.
98
+
99
+ Args:
100
+ route_id (int): Camptocamp route ID.
101
+
102
+ Returns:
103
+ Dict: Full route document with metadata and description.
104
+ """
105
+ return self._request(f"/routes/{route_id}/{self.language}", {})
106
+
107
+ def search_waypoints(
108
+ self,
109
+ bbox: Tuple[float, float, float, float],
110
+ limit: int = 10,
111
+ ) -> Dict[str, Any]:
112
+ """
113
+ Get waypoints (e.g., huts, summits) within a given area.
114
+
115
+ Args:
116
+ bbox (Tuple[float, float, float, float]): Bounding box as (west, south, east, north).
117
+ limit (int): Max number of results.
118
+
119
+ Returns:
120
+ Dict: API response with waypoint data.
121
+ """
122
+ params = {
123
+ "bbox": ",".join(map(str, bbox)),
124
+ "limit": limit,
125
+ }
126
+ return self._request("/waypoints", params)
main.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This is a sample Python script.
2
+
3
+ # Press ⌃R to execute it or replace it with your code.
4
+ # Press Double ⇧ to search everywhere for classes, files, tool windows, actions, and settings.
5
+
6
+
7
+ def print_hi(name):
8
+ # Use a breakpoint in the code line below to debug your script.
9
+ print(f'Hi, {name}') # Press ⌘F8 to toggle the breakpoint.
10
+
11
+
12
+ # Press the green button in the gutter to run the script.
13
+ if __name__ == '__main__':
14
+ print_hi('PyCharm')
15
+
16
+ # See PyCharm help at https://www.jetbrains.com/help/pycharm/
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio>=4.0
2
+ requests>=2.0