aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar kwzrd <[email protected]>2020-03-14 17:24:38 +0100
committerGravatar kwzrd <[email protected]>2020-03-14 17:24:38 +0100
commite723dd242b8c040d8649cee8c26e000791e5c88a (patch)
treea157ceedb8d7d451021dd1af8992907c4d01fafa
parentDeseasonify: lock daily tasks to their seasons' respective months (diff)
Deseasonify: add convenience method to get current season
-rw-r--r--bot/seasons/__init__.py24
1 files changed, 22 insertions, 2 deletions
diff --git a/bot/seasons/__init__.py b/bot/seasons/__init__.py
index 21b7f6fe..2f7609ec 100644
--- a/bot/seasons/__init__.py
+++ b/bot/seasons/__init__.py
@@ -1,11 +1,12 @@
import logging
import pkgutil
+from datetime import datetime
from pathlib import Path
-from typing import List, Set
+from typing import List, Set, Type
from bot.constants import Month
-__all__ = ("SeasonBase", "get_seasons", "get_extensions")
+__all__ = ("SeasonBase", "get_seasons", "get_extensions", "get_current_season")
log = logging.getLogger(__name__)
@@ -62,3 +63,22 @@ class SeasonBase:
branding_path: str = "seasonal/evergreen"
months: Set[Month] = set(Month)
+
+
+def get_current_season() -> Type[SeasonBase]:
+ """Give active season, based on current UTC month."""
+ current_month = Month(datetime.utcnow().month)
+
+ active_seasons = tuple(
+ season
+ for season in SeasonBase.__subclasses__()
+ if current_month in season.months
+ )
+
+ if not active_seasons:
+ return SeasonBase
+
+ if len(active_seasons) > 1:
+ log.warning(f"Multiple active season in month {current_month.name}")
+
+ return active_seasons[0]