Resolve instance URL on getting admin account

main
Bofh 3 months ago
parent ea1eece550
commit 07da08e07c

@ -6,6 +6,7 @@ import time
import json
import sys
import os
import re
DOMAIN = 'mastodon.social'
@ -98,8 +99,18 @@ def cache_write(f,o):
pickle.dump(o, out_file)
return True
def resolve_instance_url(domain):
r = http_get('https://'+domain+'/.well-known/host-meta')
for l in r.text.splitlines():
l = l.strip()
if '.well-known/webfinger' in l:
i_url = re.search(r'(?<=\=")https?:\/\/[^\/]+',l).group(0)
return i_url
return 'https://'+domain
def get_admin_account(domain):
r = http_get('https://'+domain+'/api/v1/instance')
url = resolve_instance_url(domain)
r = http_get(url+'/api/v1/instance')
if r == False:
return False
js = json.loads(r.text)

Loading…
Cancel
Save