style: refactor codebase to adhere to PEP 8 formatting standards throughout all source files
This commit is contained in:
@@ -4,6 +4,7 @@ from mcp.types import TextContent, Annotations, EmbeddedResource, TextResourceCo
|
||||
from strava_mcp_server.strava_client import StravaClient
|
||||
from strava_mcp_server.utils import format_date_iso, format_date_human
|
||||
|
||||
|
||||
def register(mcp: FastMCP, strava: StravaClient) -> None:
|
||||
@mcp.tool()
|
||||
async def get_athlete_profile(ctx: Context):
|
||||
@@ -12,12 +13,19 @@ def register(mcp: FastMCP, strava: StravaClient) -> None:
|
||||
Returns name, city, country, follower count, and other profile details.
|
||||
"""
|
||||
try:
|
||||
|
||||
await ctx.info("Fetching athlete profile...")
|
||||
|
||||
athlete = await strava.get_athlete()
|
||||
|
||||
location_parts = [p for p in (athlete.get('city'), athlete.get('state'), athlete.get('country')) if p]
|
||||
location_parts = [
|
||||
p
|
||||
for p in (
|
||||
athlete.get("city"),
|
||||
athlete.get("state"),
|
||||
athlete.get("country"),
|
||||
)
|
||||
if p
|
||||
]
|
||||
location = ", ".join(location_parts) if location_parts else "N/A"
|
||||
|
||||
essential_data = {
|
||||
@@ -38,33 +46,33 @@ def register(mcp: FastMCP, strava: StravaClient) -> None:
|
||||
}
|
||||
|
||||
markdown_summary = f"""
|
||||
👤 **Profile for {essential_data['name']}** (ID: {essential_data['id']})
|
||||
- Username: {essential_data['username'] or 'N/A'}
|
||||
- Location: {essential_data['location']}
|
||||
- Sex: {essential_data['sex'] or 'N/A'}
|
||||
- Weight: {essential_data['weight'] or 'N/A'} kg
|
||||
- Measurement Units: {essential_data['measurement_units'] or 'N/A'}
|
||||
- Strava Summit Member: {'Yes' if essential_data['is_premium'] else 'No'}
|
||||
- Profile Image (Medium): {essential_data['profile_medium'] or 'N/A'}
|
||||
- Joined Strava: {format_date_human(essential_data['created_at'])}
|
||||
- Last Updated: {format_date_human(essential_data['updated_at'])}
|
||||
👤 **Profile for {essential_data["name"]}** (ID: {essential_data["id"]})
|
||||
- Username: {essential_data["username"] or "N/A"}
|
||||
- Location: {essential_data["location"]}
|
||||
- Sex: {essential_data["sex"] or "N/A"}
|
||||
- Weight: {essential_data["weight"] or "N/A"} kg
|
||||
- Measurement Units: {essential_data["measurement_units"] or "N/A"}
|
||||
- Strava Summit Member: {"Yes" if essential_data["is_premium"] else "No"}
|
||||
- Profile Image (Medium): {essential_data["profile_medium"] or "N/A"}
|
||||
- Joined Strava: {format_date_human(essential_data["created_at"])}
|
||||
- Last Updated: {format_date_human(essential_data["updated_at"])}
|
||||
""".strip()
|
||||
|
||||
return [
|
||||
TextContent(
|
||||
type="text",
|
||||
type="text",
|
||||
text=markdown_summary,
|
||||
annotations=Annotations(audience=["user"])
|
||||
annotations=Annotations(audience=["user"]),
|
||||
),
|
||||
EmbeddedResource(
|
||||
type="resource",
|
||||
resource=TextResourceContents(
|
||||
uri="internal://athlete/profile",
|
||||
mimeType="application/json",
|
||||
text=json.dumps(essential_data, indent=2)
|
||||
text=json.dumps(essential_data, indent=2),
|
||||
),
|
||||
annotations=Annotations(audience=["assistant"])
|
||||
)
|
||||
annotations=Annotations(audience=["assistant"]),
|
||||
),
|
||||
]
|
||||
|
||||
except Exception as e:
|
||||
@@ -81,9 +89,9 @@ def register(mcp: FastMCP, strava: StravaClient) -> None:
|
||||
try:
|
||||
await ctx.info("Fetching athlete zones...")
|
||||
zones = await strava.get_athlete_zones()
|
||||
|
||||
|
||||
markdown_summary = "### 💓 Trainingszonen\n\n"
|
||||
|
||||
|
||||
# Heart Rate Zones
|
||||
hr_zones = zones.get("heart_rate", {}).get("zones", [])
|
||||
if hr_zones:
|
||||
@@ -91,9 +99,9 @@ def register(mcp: FastMCP, strava: StravaClient) -> None:
|
||||
markdown_summary += "| Zone | Bereich (bpm) |\n"
|
||||
markdown_summary += "|------|---------------|\n"
|
||||
for i, z in enumerate(hr_zones):
|
||||
markdown_summary += f"| {i+1} | {z.get('min')} - {z.get('max') if z.get('max') != -1 else 'max'} |\n"
|
||||
markdown_summary += f"| {i + 1} | {z.get('min')} - {z.get('max') if z.get('max') != -1 else 'max'} |\n"
|
||||
markdown_summary += "\n"
|
||||
|
||||
|
||||
# Power Zones
|
||||
power_zones = zones.get("power", {}).get("zones", [])
|
||||
if power_zones:
|
||||
@@ -101,26 +109,26 @@ def register(mcp: FastMCP, strava: StravaClient) -> None:
|
||||
markdown_summary += "| Zone | Bereich (W) |\n"
|
||||
markdown_summary += "|------|-------------|\n"
|
||||
for i, z in enumerate(power_zones):
|
||||
markdown_summary += f"| {i+1} | {z.get('min')} - {z.get('max') if z.get('max') != -1 else 'max'} |\n"
|
||||
markdown_summary += f"| {i + 1} | {z.get('min')} - {z.get('max') if z.get('max') != -1 else 'max'} |\n"
|
||||
|
||||
if not hr_zones and not power_zones:
|
||||
markdown_summary = "⚠️ Keine Trainingszonen konfiguriert."
|
||||
|
||||
return [
|
||||
TextContent(
|
||||
type="text",
|
||||
type="text",
|
||||
text=markdown_summary.strip(),
|
||||
annotations=Annotations(audience=["user"])
|
||||
annotations=Annotations(audience=["user"]),
|
||||
),
|
||||
EmbeddedResource(
|
||||
type="resource",
|
||||
resource=TextResourceContents(
|
||||
uri="internal://athlete/zones",
|
||||
mimeType="application/json",
|
||||
text=json.dumps(zones, indent=2)
|
||||
text=json.dumps(zones, indent=2),
|
||||
),
|
||||
annotations=Annotations(audience=["assistant"])
|
||||
)
|
||||
annotations=Annotations(audience=["assistant"]),
|
||||
),
|
||||
]
|
||||
except Exception as e:
|
||||
error_msg = f"Error fetching athlete zones: {str(e)}"
|
||||
@@ -163,7 +171,7 @@ def register(mcp: FastMCP, strava: StravaClient) -> None:
|
||||
}
|
||||
|
||||
markdown_summary = "### 📈 Trainingsstatistiken\n\n"
|
||||
|
||||
|
||||
def create_table(title: str, data: dict):
|
||||
tbl = f"#### {title}\n"
|
||||
tbl += "| Sport | Aktivitäten | Distanz | Zeit | Höhenmeter |\n"
|
||||
@@ -179,19 +187,19 @@ def register(mcp: FastMCP, strava: StravaClient) -> None:
|
||||
|
||||
return [
|
||||
TextContent(
|
||||
type="text",
|
||||
type="text",
|
||||
text=markdown_summary.strip(),
|
||||
annotations=Annotations(audience=["user"])
|
||||
annotations=Annotations(audience=["user"]),
|
||||
),
|
||||
EmbeddedResource(
|
||||
type="resource",
|
||||
resource=TextResourceContents(
|
||||
uri="internal://athlete/stats",
|
||||
mimeType="application/json",
|
||||
text=json.dumps(stats, indent=2)
|
||||
text=json.dumps(stats, indent=2),
|
||||
),
|
||||
annotations=Annotations(audience=["assistant"])
|
||||
)
|
||||
annotations=Annotations(audience=["assistant"]),
|
||||
),
|
||||
]
|
||||
except Exception as e:
|
||||
error_msg = f"Error fetching athlete stats: {str(e)}"
|
||||
|
||||
Reference in New Issue
Block a user