From bfbd05a3e86d874e59fe66d51583aa021b3b96fd Mon Sep 17 00:00:00 2001 From: Jeffrey Goldberg Date: Sun, 26 Nov 2023 16:25:00 -0600 Subject: [PATCH] WIP: more mast parsing --- rendercv/data_model.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/rendercv/data_model.py b/rendercv/data_model.py index cbcdfd1..d1a861f 100644 --- a/rendercv/data_model.py +++ b/rendercv/data_model.py @@ -1068,8 +1068,8 @@ class Connection(BaseModel): value: str @staticmethod - def MastodonUname2Url(uname: str) ->Optional[HttpUrl]: - """From a Mastodon-style "user@domain.example" returns profile url.""" + def MastodonUname2Url(id: str) -> Optional[HttpUrl]: + """From a Mastodon id "user@domain.example" returns profile url.""" # The closest thing to a formal spec of Mastodon usernames # where these regular expressions from a (reference?) @@ -1077,10 +1077,24 @@ class Connection(BaseModel): # # https://github.com/mastodon/mastodon/blob/852123867768e23410af5bd07ac0327bead0d9b2/app/models/account.rb#L68 # + # USERNAME_RE = /[a-z0-9_]+([a-z0-9_.-]+[a-z0-9_]+)?/i # SERNAME_RE = /[a-z0-9_]+([a-z0-9_.-]+[a-z0-9_]+)?/i # MENTION_RE = %r{(?[a-z0-9_]+([a-z0-9_.-]+[a-z0-9_]+)?) # username part + @ # separator + (?P[a-z0-9_]+([a-z0-9_.-]+[a-z0-9_]+)?) # domain part + """, re.VERBOSE | re.IGNORECASE) + + m = pattern.match(id) + uname = m.group("uname") + domain = m.group("domain") + + url = HttpUrl(f'https://{domain}/@{uname}') + return url @computed_field @cached_property @@ -1094,7 +1108,7 @@ class Connection(BaseModel): elif self.name == "Orcid": url = f"https://orcid.org/{self.value}" elif self.name == "Mastodon": - url = MastodonUname2Url(self.value) + url = self.MastodonUname2Url(self.value) elif self.name == "email": url = f"mailto:{self.value}" elif self.name == "website":