mirror of https://gitlab.com/bashrc2/epicyon
Broch mode elapses
parent
68d3f3ee91
commit
6b55ceab12
30
blocking.py
30
blocking.py
|
@ -7,6 +7,8 @@ __email__ = "bob@freedombone.net"
|
||||||
__status__ = "Production"
|
__status__ = "Production"
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
from datetime import datetime
|
||||||
|
from utils import fileLastModified
|
||||||
from utils import setConfigParam
|
from utils import setConfigParam
|
||||||
from utils import hasUsersPath
|
from utils import hasUsersPath
|
||||||
from utils import getFullDomain
|
from utils import getFullDomain
|
||||||
|
@ -374,6 +376,7 @@ def setBrochMode(baseDir: str, domainFull: str, enabled: bool) -> None:
|
||||||
# remove instance allow list
|
# remove instance allow list
|
||||||
if os.path.isfile(allowFilename):
|
if os.path.isfile(allowFilename):
|
||||||
os.remove(allowFilename)
|
os.remove(allowFilename)
|
||||||
|
print('Broch mode turned off')
|
||||||
else:
|
else:
|
||||||
# generate instance allow list
|
# generate instance allow list
|
||||||
allowedDomains = [domainFull]
|
allowedDomains = [domainFull]
|
||||||
|
@ -405,5 +408,32 @@ def setBrochMode(baseDir: str, domainFull: str, enabled: bool) -> None:
|
||||||
for d in allowedDomains:
|
for d in allowedDomains:
|
||||||
allowFile.write(d + '\n')
|
allowFile.write(d + '\n')
|
||||||
allowFile.close()
|
allowFile.close()
|
||||||
|
print('Broch mode enabled')
|
||||||
|
|
||||||
setConfigParam(baseDir, "brochMode", enabled)
|
setConfigParam(baseDir, "brochMode", enabled)
|
||||||
|
|
||||||
|
|
||||||
|
def brochModeLapses(baseDir: str, lapseDays=7) -> None:
|
||||||
|
"""After broch mode is enabled it automatically
|
||||||
|
elapses after a period of time
|
||||||
|
"""
|
||||||
|
allowFilename = baseDir + '/accounts/allowedinstances.txt'
|
||||||
|
if not os.path.isfile(allowFilename):
|
||||||
|
return
|
||||||
|
lastModified = fileLastModified(allowFilename)
|
||||||
|
modifiedDate = None
|
||||||
|
try:
|
||||||
|
modifiedDate = \
|
||||||
|
datetime.strptime(lastModified, "%Y-%m-%dT%H:%M:%SZ")
|
||||||
|
except BaseException:
|
||||||
|
return
|
||||||
|
if not modifiedDate:
|
||||||
|
return
|
||||||
|
currTime = datetime.datetime.utcnow()
|
||||||
|
daysSinceBroch = (currTime - modifiedDate).days
|
||||||
|
if daysSinceBroch >= lapseDays:
|
||||||
|
try:
|
||||||
|
os.remove(allowFilename)
|
||||||
|
print('Broch mode has elapsed')
|
||||||
|
except BaseException:
|
||||||
|
pass
|
||||||
|
|
3
inbox.py
3
inbox.py
|
@ -51,6 +51,7 @@ from bookmarks import updateBookmarksCollection
|
||||||
from bookmarks import undoBookmarksCollectionEntry
|
from bookmarks import undoBookmarksCollectionEntry
|
||||||
from blocking import isBlocked
|
from blocking import isBlocked
|
||||||
from blocking import isBlockedDomain
|
from blocking import isBlockedDomain
|
||||||
|
from blocking import brochModeLapses
|
||||||
from filters import isFiltered
|
from filters import isFiltered
|
||||||
from utils import updateAnnounceCollection
|
from utils import updateAnnounceCollection
|
||||||
from utils import undoAnnounceCollectionEntry
|
from utils import undoAnnounceCollectionEntry
|
||||||
|
@ -2518,6 +2519,8 @@ def runInboxQueue(recentPostsCache: {}, maxRecentPosts: int,
|
||||||
# heartbeat to monitor whether the inbox queue is running
|
# heartbeat to monitor whether the inbox queue is running
|
||||||
heartBeatCtr += 5
|
heartBeatCtr += 5
|
||||||
if heartBeatCtr >= 10:
|
if heartBeatCtr >= 10:
|
||||||
|
# turn off broch mode after it has timed out
|
||||||
|
brochModeLapses(baseDir)
|
||||||
print('>>> Heartbeat Q:' + str(len(queue)) + ' ' +
|
print('>>> Heartbeat Q:' + str(len(queue)) + ' ' +
|
||||||
'{:%F %T}'.format(datetime.datetime.now()))
|
'{:%F %T}'.format(datetime.datetime.now()))
|
||||||
heartBeatCtr = 0
|
heartBeatCtr = 0
|
||||||
|
|
Loading…
Reference in New Issue