mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-09-25 08:44:33 +00:00
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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user