def title_to_link(card): # This assumes your link is in card.name somewhere sp = card.name.split() links = [n for n in sp if VALID_URL_REGEX.search(n)] existing_attachments = [a.name for a in card.get_attachments()] user_parameters = {'oldname': card.name} for idx, link_name in enumerate(links): # Attach this link if link_name not in existing_attachments: card.attach(url=link_name) # Get the URL & title of the link for the user to access in the renaming interface user_parameters['link{}'.format(idx)] = link_name possible_title = get_title_of_webpage(link_name) if possible_title: user_parameters['title{}'.format(idx)] = possible_title # Give the user a default title without the link, but allow them to use the title of the page from a link as a var instead reconstructed = ' '.join([n for n in sp if not VALID_URL_REGEX.search(n)]) CardTool.rename(card, variables=user_parameters)
def title_to_link(self): # This assumes your link is in card.name somewhere sp = self.card_json['name'].split() links = [n for n in sp if VALID_URL_REGEX.search(n)] existing_attachments = [a['name'] for a in self.fetch_attachments()] user_parameters = {'oldname': self.card_json['name']} for idx, link_name in enumerate(links): # Attach this link if link_name not in existing_attachments: self.attach_url(link_name) # Get the URL & title of the link for the user to access in the renaming interface user_parameters[f'link{idx}'] = link_name possible_title = get_title_of_webpage(link_name) if possible_title: user_parameters[f'title{idx}'] = possible_title # Give the user a default title without the link, but allow them to use the title of the page from a link as a var instead reconstructed = ' '.join([n for n in sp if not VALID_URL_REGEX.search(n)]) self.rename(variables=user_parameters, default=reconstructed)
def title_to_link(card): # This assumes your link is in card.name somewhere sp = card.name.split() links = [n for n in sp if VALID_URL_REGEX.search(n)] existing_attachments = [a.name for a in card.get_attachments()] user_parameters = {'oldname': card.name} for idx, link_name in enumerate(links): # Attach this link if link_name not in existing_attachments: card.attach(url=link_name) # Get the URL & title of the link for the user to access in the renaming interface user_parameters['link{}'.format(idx)] = link_name possible_title = get_title_of_webpage(link_name) if possible_title: user_parameters['title{}'.format(idx)] = possible_title # Give the user a default title without the link, but allow them to use the title of the page from a link as a var instead reconstructed = ' '.join( [n for n in sp if not VALID_URL_REGEX.search(n)]) CardTool.rename(card, reconstructed, user_parameters)