New arguments to handle cache expiration

This commit is contained in:
nemunaire 2022-12-30 19:54:21 +01:00
commit f79022b7a3
5 changed files with 65 additions and 25 deletions

19
main.py
View file

@ -45,7 +45,7 @@ class WidgetPlacement:
self.kwargs = kwargs
def main(only_on_coming_evt=False, ignore_module=[]):
def main(only_on_coming_evt=False, ignore_module=[], **config_args):
image = Image.new('1', (480, 800), 255)
#image = Image.new('L', (480, 800), 'white')
draw = ImageDraw.Draw(image)
@ -53,7 +53,7 @@ def main(only_on_coming_evt=False, ignore_module=[]):
shape = []
import modules
config = modules.Config()
config = modules.Config(**config_args)
# alerts
alerts = []
@ -99,14 +99,14 @@ def main(only_on_coming_evt=False, ignore_module=[]):
# RATP weather
from modules.ratp import RATPWeatherModule
shape.append(WidgetPlacement(RATPWeatherModule, size=(int(480/1.6), 94), position=(480-int(480/1.6), 155)))
alerts.append(RATPWeatherModule)
alerts.append({"module": RATPWeatherModule, "args_func": [config]})
# Toolbar
from modules.weather import WeatherToolbarModule
shape.append(WidgetPlacement(WeatherToolbarModule, size=(480, 50), position=(0, 530)))
from modules.sncf import SNCFWeatherModule
alerts.append({"module": SNCFWeatherModule, "args": "normandie"})
alerts.append({"module": SNCFWeatherModule, "args_func": [config, "normandie"]})
from modules.weather import WeatherAlerts
alerts.append(WeatherAlerts)
@ -193,7 +193,16 @@ if __name__ == '__main__':
help='Ignore the given modules')
parser.add_argument('--only-on-coming-evt', '-O', action='store_const', const=True,
help='Refresh screen only if there is upcoming event')
parser.add_argument('--cache-timeout', '-C', type=int, default=90,
help='How many minutes to keep the infos in cache')
parser.add_argument('--max-cache-timeout', type=int, default=120,
help='Maximum time to serve the infos in cache in case of issue')
args = parser.parse_args()
main(args.only_on_coming_evt, args.ignore_module)
main(
args.only_on_coming_evt,
args.ignore_module,
cache_timeout=args.cache_timeout,
max_cache_timeout=args.max_cache_timeout,
)