Files
spothole/core/activity_utils.py
T

44 lines
1.6 KiB
Python

from data.activities import ACTIVITIES
def get_activity_by_name(name):
"""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."""
if not name:
return None
for activity_name, activity in ACTIVITIES.items():
if activity_name.upper() == name.upper():
return activity
return None
def get_ref_regex_for_activity(activity):
"""Utility function to get the regex string for an activity reference for a named activity. If no match is
found, None will be returned."""
found = get_activity_by_name(activity)
return found.ref_regex if found else None
def get_icon_for_activity(activity):
"""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)
return found.icon if found else None
def get_activity_name_from_comment_name(activity):
"""Utility function to get the name of an activity from its "comment name". Generally these will be the same
but there are some cases (e.g. is "TOTA" Towers, Tiles or Toilets?) where we need to transform one to the
other."""
for activity_name, a in ACTIVITIES.items():
if any(n.upper() == activity.upper() for n in a.comment_names):
return activity_name
return None
# Regex matching any activity's "comment name", i.e. how it may be referred to in spot comments
ANY_ACTIVITY_REGEX = rf"({'|'.join(n for a in ACTIVITIES.values() for n in a.comment_names)})"