v1.6.0: max_bot fixes — feature keys, flush→commit, test-run, categories, broadcast page, proxy error handling, deploy scripts
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import re
|
||||
from typing import Optional
|
||||
|
||||
|
||||
def render_template(template: str, **kwargs) -> str:
|
||||
result = template
|
||||
for key, value in kwargs.items():
|
||||
result = result.replace("{" + key + "}", str(value))
|
||||
remaining = re.findall(r'\{(\w+)\}', result)
|
||||
for var in remaining:
|
||||
result = result.replace("{" + var + "}", "")
|
||||
return result
|
||||
|
||||
|
||||
def parse_link_text(text: str) -> str:
|
||||
text = re.sub(r'\[([^\]]+)\]\(tel:[^\)]+\)', r'\1', text)
|
||||
text = re.sub(r'\[([^\]]+)\]\(mailto:[^\)]+\)', r'\1', text)
|
||||
text = re.sub(r'\[([^\]]+)\]\(https?://[^\)]+\)', r'\1', text)
|
||||
return text
|
||||
|
||||
|
||||
def make_clickable_links(text: str, phone_1: str = "", phone_2: str = "",
|
||||
email: str = "", email_subject: str = "") -> str:
|
||||
phone_1_raw = re.sub(r'[^\d+]', '', phone_1)
|
||||
phone_2_raw = re.sub(r'[^\d+]', '', phone_2)
|
||||
email_encoded = email.replace(' ', '%20')
|
||||
subject_encoded = email_subject.replace(' ', '%20')
|
||||
|
||||
text = text.replace("{phone_1_raw}", phone_1_raw)
|
||||
text = text.replace("{phone_2_raw}", phone_2_raw)
|
||||
text = text.replace("{email_encoded}", email_encoded)
|
||||
text = text.replace("{email_subject_encoded}", subject_encoded)
|
||||
|
||||
return text
|
||||
Reference in New Issue
Block a user