Strict adherence to canonical ActivityNames, to avoid the problem where Spothole was giving out activities like ["Towers", "TOWERS"]. All uses of ActivityName should now be canonical not arbitrary strings, and attempts to convert unknown strings to activitynames will be logged for me to check out.

This commit is contained in:
Ian Renton
2026-09-25 09:16:53 +01:00
parent 7417140a3d
commit 760c2412d3
17 changed files with 144 additions and 145 deletions
+9 -3
View File
@@ -1,7 +1,12 @@
import logging
from data.activities import ACTIVITIES
from data.activity import Activity
logger = logging.getLogger(__name__)
def get_activity_by_name(name):
def get_activity_by_name(name: str | None) -> Activity | None:
"""Utility function to resolve an arbitrary, case-insensitive activity name string (e.g. from a spot comment, a
provider, or an API request) to the matching known Activity. Returns None if no match is found."""
@@ -10,10 +15,11 @@ def get_activity_by_name(name):
for activity_name, activity in ACTIVITIES.items():
if activity_name.upper() == name.upper():
return activity
logger.warning(f"Unknown activity name '{name}', developer may need to add support for this!")
return None
def get_ref_regex_for_activity(activity):
def get_ref_regex_for_activity(activity: str | None) -> str | None:
"""Utility function to get the regex string for an activity reference for a named activity. If no match is
found, None will be returned."""
@@ -21,7 +27,7 @@ def get_ref_regex_for_activity(activity):
return found.ref_regex if found else None
def get_icon_for_activity(activity):
def get_icon_for_activity(activity: str | None) -> str | None:
"""Utility function to get the icon for a named activity. If no match is found, None will be returned."""
found = get_activity_by_name(activity)