From b8c957eb3824bc39e3cde15778854bd76f24b094 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Thu, 21 Oct 2021 12:13:24 +0100 Subject: [PATCH] Load cw lists at startup --- blocking.py | 22 ++++++++++++++++++++++ daemon.py | 2 ++ 2 files changed, 24 insertions(+) diff --git a/blocking.py b/blocking.py index 5c70ca676..da372f8af 100644 --- a/blocking.py +++ b/blocking.py @@ -874,3 +874,25 @@ def brochModeLapses(baseDir: str, lapseDays: int = 7) -> bool: print('Broch mode has elapsed') return True return False + + +def loadLists(baseDir: str, verbose: bool) -> {}: + """Load lists used for blocking or warnings + """ + if not os.path.isdir(baseDir + '/lists'): + return {} + result = {} + for subdir, dirs, files in os.walk(baseDir + '/lists'): + for f in files: + if not f.endswith('.json'): + continue + listFilename = os.path.join(baseDir + '/lists', f) + listJson = loadJson(listFilename) + if not listJson: + continue + if listJson.get('name') and listJson.get('domains'): + name = listJson['name'] + if verbose: + print('List: ' + name) + result[name] = listJson + return result diff --git a/daemon.py b/daemon.py index 034047507..c382f1481 100644 --- a/daemon.py +++ b/daemon.py @@ -125,6 +125,7 @@ from media import replaceTwitter from media import attachMedia from media import pathIsVideo from media import pathIsAudio +from blocking import loadLists from blocking import updateBlockedCache from blocking import mutePost from blocking import unmutePost @@ -17164,6 +17165,7 @@ def runDaemon(defaultReplyIntervalHours: int, updateBlockedCache(baseDir, httpd.blockedCache, httpd.blockedCacheLastUpdated, httpd.blockedCacheUpdateSecs) + httpd.lists = loadLists(baseDir, True) # cache to store css files httpd.cssCache = {}