From 9907432a0a743cae9bb8008f545d32dac3deee73 Mon Sep 17 00:00:00 2001 From: Raffson Date: Sat, 18 Nov 2023 23:46:38 +0100 Subject: [PATCH] Add sunrise-sunset times on kneeboard --- game/missiongenerator/kneeboard.py | 18 ++++++++++++++++++ requirements.txt | 1 + 2 files changed, 19 insertions(+) diff --git a/game/missiongenerator/kneeboard.py b/game/missiongenerator/kneeboard.py index 6e3bace2..eae7ef27 100644 --- a/game/missiongenerator/kneeboard.py +++ b/game/missiongenerator/kneeboard.py @@ -32,6 +32,7 @@ from typing import Dict, Iterator, List, Optional, TYPE_CHECKING, Tuple from PIL import Image, ImageDraw, ImageFont from dcs.mission import Mission +from suntime import Sun from tabulate import tabulate from game.ato.flighttype import FlightType @@ -431,6 +432,23 @@ class BriefingPage(KneeboardPage): fl = self.flight + start_pos = fl.waypoints[0].position.latlng() + sun = Sun(start_pos.lat, start_pos.lng) + + date = fl.squadron.coalition.game.date + tz = fl.squadron.coalition.game.theater.timezone + + # Get today's sunrise and sunset in UTC + sr_utc = sun.get_sunrise_time(date) + ss_utc = sun.get_sunset_time(date) + sr = sr_utc + tz.utcoffset(sun.get_sunrise_time(date)) + ss = ss_utc + tz.utcoffset(sun.get_sunset_time(date)) + + writer.text( + f"Sunrise - Sunset: {sr.strftime('%H:%M')} - {ss.strftime('%H:%M')}" + f" ({sr_utc.strftime('%H:%M')} - {ss_utc.strftime('%H:%M')} UTC)" + ) + if fl.bingo_fuel and fl.joker_fuel: writer.table( [ diff --git a/requirements.txt b/requirements.txt index cea96cd6..0d695021 100644 --- a/requirements.txt +++ b/requirements.txt @@ -52,6 +52,7 @@ shiboken6==6.4.3 six==1.16.0 sniffio==1.3.0 starlette==0.27.0 +suntime==1.2.5 tabulate==0.9.0 text-unidecode==1.3 toml==0.10.2