Coverage for webapp/snapcraft/logic.py: 86%
21 statements
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-30 22:06 +0000
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-30 22:06 +0000
1from datetime import datetime, timedelta
3from webapp import helpers
6def get_livestreams():
7 """
8 Get available livestreams and decide whether they should be shown
9 :returns: Dictionary of livestream details
10 """
11 livestream_to_show = None
12 livestreams = helpers.get_yaml(
13 "snapcraft/content/snapcraft_live.yaml", typ="safe"
14 )
16 if livestreams:
17 now = datetime.now()
18 lead_time = 4 # 4 days
19 cooldown_time = 2 # 2 days
21 for livestream in livestreams:
22 instance_lead_time = lead_time
23 if "lead_time" in livestream:
24 instance_lead_time = livestream["lead_time"]
26 instance_cooldown_time = cooldown_time
27 if "cooldown_time" in livestream:
28 instance_cooldown_time = livestream["cooldown_time"]
30 show_from = livestream["time"] - timedelta(days=instance_lead_time)
31 show_until = livestream["time"] + timedelta(
32 days=instance_cooldown_time
33 )
35 if show_from < now and show_until > now:
36 livestream_to_show = livestream
38 return livestream_to_show