Populate last seen files on startup

alt-html-css
Bob Mottram 2020-12-13 22:01:10 +00:00
parent 966dff9921
commit 12cccfdeb6
2 changed files with 39 additions and 0 deletions

View File

@ -89,6 +89,7 @@ from inbox import getPersonPubKey
from follow import getFollowingFeed from follow import getFollowingFeed
from follow import sendFollowRequest from follow import sendFollowRequest
from follow import unfollowPerson from follow import unfollowPerson
from follow import createInitialLastSeen
from auth import authorize from auth import authorize
from auth import createPassword from auth import createPassword
from auth import createBasicAuthHeader from auth import createBasicAuthHeader
@ -13261,6 +13262,8 @@ def runDaemon(dormantMonths: int,
httpd.iconsCache = {} httpd.iconsCache = {}
httpd.fontsCache = {} httpd.fontsCache = {}
createInitialLastSeen(baseDir, httpPrefix)
print('Creating inbox queue') print('Creating inbox queue')
httpd.thrInboxQueue = \ httpd.thrInboxQueue = \
threadWithTrace(target=runInboxQueue, threadWithTrace(target=runInboxQueue,

View File

@ -27,6 +27,42 @@ from auth import createBasicAuthHeader
from session import postJson from session import postJson
def createInitialLastSeen(baseDir: str, httpPrefix: str) -> None:
"""Creates initial lastseen files for all follows
"""
for subdir, dirs, files in os.walk(baseDir + '/accounts'):
for acct in dirs:
if '@' not in acct:
continue
if 'inbox@' in acct or 'news@' in acct:
continue
accountDir = os.path.join(baseDir + '/accounts', acct)
followingFilename = accountDir + '/following.txt'
if not os.path.isfile(followingFilename):
continue
lastSeenDir = accountDir + '/lastseen'
if not os.path.isdir(lastSeenDir):
os.mkdir(lastSeenDir)
with open(followingFilename, 'r') as fp:
followingHandles = fp.readlines()
for handle in followingHandles:
if '#' in handle:
continue
if '@' not in handle:
continue
nickname = handle.split('@')[0]
domain = handle.split('@')[1]
actor = \
httpPrefix + '://' + \
nickname + '@' + domain + '/users/' + nickname
lastSeenFilename = \
lastSeenDir + '/' + actor.replace('/', '#') + '.txt'
if not os.path.isfile(lastSeenFilename):
with open(lastSeenFilename, 'w+') as fp:
fp.write(str(0))
break
def preApprovedFollower(baseDir: str, def preApprovedFollower(baseDir: str,
nickname: str, domain: str, nickname: str, domain: str,
approveHandle: str, approveHandle: str,