Publish directory on mastodon api

merge-requests/26/head
Bob Mottram 2021-07-31 16:07:52 +01:00
parent f4e479c423
commit ab61eb7d8d
1 changed files with 57 additions and 0 deletions

View File

@ -11,9 +11,63 @@ import os
from utils import loadJson
from utils import getConfigParam
from utils import acctDir
from utils import isAccountDir
from metadata import metaDataInstance
def _getMastApiV1Directory(baseDir: str, domain: str) -> []:
mastoDirectory = []
ctr = 1
for subdir, dirs, files in os.walk(baseDir + '/accounts'):
for acct in dirs:
if not isAccountDir(acct):
continue
actorFilename = \
os.path.join(baseDir + '/accounts', acct + '.json')
if not os.path.isfile(actorFilename):
continue
actorJson = loadJson(actorFilename, 0, 1)
if not actorJson:
continue
if not actorJson.get('discoverable'):
continue
isGroup = False
if actorJson['type'] != 'Person' and actorJson['type'] != 'Group':
continue
if actorJson['type'] == 'Group':
isGroup = True
isLocked = False
if actorJson.get('manuallyApprovesFollowers'):
isLocked = True
isBot = False
acct = {
"id": ctr,
"username": actorJson['preferredUsername'],
"acct": actorJson['preferredUsername'] + "@" + domain,
"display_name": actorJson['name'],
"locked": isLocked,
"bot": isBot,
"discoverable": True,
"group": isGroup,
"created_at": actorJson['published'],
"note": actorJson['summary'],
"url": actorJson['url'],
"avatar": actorJson['icon']['url'],
"avatar_static": actorJson['icon']['url'],
"header": actorJson['image']['url'],
"header_static": actorJson['image']['url'],
"followers_count": 999,
"following_count": 999,
"statuses_count": 999,
"last_status_at": "2021-07-31",
"emojis": []
}
mastoDirectory.append(acct)
ctr += 1
break
return mastoDirectory
def _getMastApiV1Id(path: str) -> int:
"""Extracts the mastodon Id number from the given path
"""
@ -158,6 +212,9 @@ def mastoApiV1Response(path: str, callingDomain: str,
elif path.startswith('/api/v1/reports'):
sendJson = []
sendJsonStr = 'masto API reports sent'
elif path.startswith('/api/v1/directory'):
sendJson = _getMastApiV1Directory(baseDir, domain)
sendJsonStr = 'masto API directory sent'
elif path.startswith('/api/v1/statuses'):
sendJson = []
sendJsonStr = 'masto API statuses sent'