mirror of
https://codeberg.org/privacy1st/MastodonTootFollower
synced 2024-12-22 23:06:05 +01:00
support for two different Toot URLs
This commit is contained in:
parent
9b4e7a0603
commit
ded58add59
@ -2,13 +2,31 @@ import re
|
|||||||
|
|
||||||
|
|
||||||
def parse_toot_url(url: str) -> tuple[str, str, str]:
|
def parse_toot_url(url: str) -> tuple[str, str, str]:
|
||||||
|
if '/users/' in url and '/statuses' in url:
|
||||||
|
return parse2(url)
|
||||||
|
else:
|
||||||
|
return parse1(url)
|
||||||
|
|
||||||
|
|
||||||
|
def parse1(url: str) -> tuple[str, str, str]:
|
||||||
"""
|
"""
|
||||||
:param url: E.g. https://mastodon.instance/@user@another.instance/123456
|
:param url: E.g. https://mastodon.instance/@username@another.instance/123456
|
||||||
:return: instance, username, toot_id
|
:return: instance, username, toot_id
|
||||||
"""
|
"""
|
||||||
|
|
||||||
pattern = re.compile(r'(^https://[^/]+)/([^/]+)/([0-9]+)$')
|
pattern = re.compile(r'(^https://[^/]+)/([^/]+)/([0-9]+)$')
|
||||||
match = pattern.match(url)
|
match = pattern.match(url)
|
||||||
if match is None:
|
if match is None:
|
||||||
raise ValueError(f'Could not parse toot url: {url}')
|
raise ValueError(f'Could not parse toot url: {url}')
|
||||||
return match.group(1), match.group(2), match.group(3)
|
return match.group(1), match.group(2), match.group(3)
|
||||||
|
|
||||||
|
|
||||||
|
def parse2(url: str) -> tuple[str, str, str]:
|
||||||
|
"""
|
||||||
|
:param url: E.g. https://mastodon.instance/users/username/statuses/123456
|
||||||
|
:return: instance, username, toot_id
|
||||||
|
"""
|
||||||
|
pattern = re.compile(r'(^https://[^/]+)/users/([^/]+)/statuses/([0-9]+)$')
|
||||||
|
match = pattern.match(url)
|
||||||
|
if match is None:
|
||||||
|
raise ValueError(f'Could not parse toot url: {url}')
|
||||||
|
return match.group(1), f'@{match.group(2)}', match.group(3)
|
||||||
|
Loading…
Reference in New Issue
Block a user