def set_note_title(self, data): """ handle the title from the data """ title = '' # if no title provided, fallback to the URL which should be provided # by any exiting service title = (data['title'] if 'title' in data else data['link']) # decode html entities if any title = HtmlEntities(title).html_entity_decode # python 2 if sys.version_info.major == 2: title = title.encode('utf8', 'xmlcharrefreplace') return title
def set_note_title(self, data): """ handle the title from the data """ title = '' # if no title provided, fallback to the URL which should be provided # by any exiting service title = (data['title'] if 'title' in data else data['link']) # decode html entities if any title = HtmlEntities(title).html_entity_decode # python 2 if sys.version_info.major == 2: title = title.encode('utf8', 'xmlcharrefreplace') return title
def save_data(self, trigger_id, **data): """ let's save the data :param trigger_id: trigger ID from which to save data :param data: the data to check to be used and save :type trigger_id: int :type data: dict :return: the status of the save statement :rtype: boolean """ self.trigger_id = trigger_id trigger = Wallabag.objects.get(trigger_id=trigger_id) title = self.set_title(data) if title is not None: # convert htmlentities title = HtmlEntities(title).html_entity_decode return self._create_entry(title, data, trigger.tag) else: # we ignore data without title so return True to let # the process continue without # raising exception return True
def save_data(self, trigger_id, **data): """ let's save the data :param trigger_id: trigger ID from which to save data :param data: the data to check to be used and save :type trigger_id: int :type data: dict :return: the status of the save statement :rtype: boolean """ if data.get('link'): if len(data.get('link')) > 0: # get the pocket data of this trigger from th_pocket.models import Pocket as PocketModel trigger = PocketModel.objects.get(trigger_id=trigger_id) title = self.set_title(data) # convert htmlentities title = HtmlEntities(title).html_entity_decode status = self._create_entry(url=data.get('link'), title=title, tags=(trigger.tag.lower())) else: logger.warning("no link provided for trigger ID {}," " so we ignore it".format(trigger_id)) status = True else: logger.critical( "no token provided for trigger ID {}".format(trigger_id)) status = False return status
def save_data(self, trigger_id, **data): """ used to save data to the service but first of all make some work about the data to find and the data to convert :param trigger_id: trigger ID from which to save data :param data: the data to check to be used and save :type trigger_id: int :type data: dict :return: the status of the save statement :rtype: boolean """ title = self.set_title(data) title = HtmlEntities(title).html_entity_decode content = self.set_content(data) content = HtmlEntities(content).html_entity_decode if data.get('output_format'): # pandoc to convert tools import pypandoc content = pypandoc.convert(content, str(data.get('output_format')), format='html') return title, content
def save_data(self, token, trigger_id, **data): """ let's save the data :param trigger_id: trigger ID from which to save data :param **data: the data to check to be used and save :type trigger_id: int :type **data: dict :return: the status of the save statement :rtype: boolean """ status = False tags = [] content = '' if token and 'link' in data and data['link'] is not None and \ len(data['link']) > 0: # get the Twitter data of this trigger trigger = Twitter.objects.get(trigger_id=trigger_id) link = data['link'] if trigger.tag: # is there several tag ? if ',' in trigger.tag: for tag in trigger.tag.split(','): tags.append('#' + tag.strip()) # no else: tags.append('#' + trigger.tag) if 'title' in data and data['title'] is not None and \ len(data['title']) > 0: title = data['title'] # decode html entities if any title = HtmlEntities(title).html_entity_decode content = str("{title} {link}").format(title=title, link=link) # TODO : need to check the size of the content and tags to add if len(tags) > 0: content += ' ' + str(','.join(tags)) try: self.twitter_api.update_status(status=content) status = True except Exception as inst: logger.critical("Twitter ERR {}".format(inst)) status = False return status
def save_data(self, trigger_id, **data): """ let's save the data :param trigger_id: trigger ID from which to save data :param data: the data to check to be used and save :type trigger_id: int :type data: dict :return: the status of the save statement :rtype: boolean """ trigger = Wallabag.objects.get(trigger_id=trigger_id) title = self.set_title(data) # convert htmlentities title = HtmlEntities(title).html_entity_decode return self._create_entry(title, data, trigger.tag)
def save_data(self, trigger_id, **data): """ let's save the data :param trigger_id: trigger ID from which to save data :param **data: the data to check to be used and save :type trigger_id: int :type **data: dict :return: the status of the save statement :rtype: boolean """ from th_wallabag.models import Wallabag status = False if self.token and 'link' in data and data['link'] is not None\ and len(data['link']) > 0: # get the data of this trigger trigger = Wallabag.objects.get(trigger_id=trigger_id) title = self.set_title(data) # convert htmlentities title = HtmlEntities(title).html_entity_decode try: self.wall.post_entries(url=data['link'], title=title, tags=(trigger.tag.lower())) sentence = str('wallabag {} created').format(data['link']) logger.debug(sentence) status = True except Exception as e: logger.critical(e) status = False else: logger.critical( "no token or link provided for trigger ID {} ".format( trigger_id)) status = False return status
def set_note_content(self, data): """ handle the content from the data """ content = '' if 'content' in data: if type(data['content']) is list or type(data['content']) is tuple\ or type(data['content']) is dict: if 'value' in data['content'][0]: content = data['content'][0].value else: if type(data['content']) is str: content = data['content'] else: # if not str or list or tuple # or dict it could be feedparser.FeedParserDict # so get the item value content = data['content']['value'] elif 'summary_detail' in data: if type(data['summary_detail']) is list or\ type(data['summary_detail']) is tuple or\ type(data['summary_detail']) is dict: if 'value' in data['summary_detail'][0]: content = data['summary_detail'][0].value else: if type(data['summary_detail']) is str: content = data['summary_detail'] else: # if not str or list or tuple # or dict it could be feedparser.FeedParserDict # so get the item value content = data['summary_detail']['value'] elif 'description' in data: content = data['description'] content = HtmlEntities(content).html_entity_decode return content
def save_data(self, token, trigger_id, **data): """ let's save the data :param trigger_id: trigger ID from which to save data :param **data: the data to check to be used and save :type trigger_id: int :type **data: dict :return: the status of the save statement :rtype: boolean """ from th_pocket.models import Pocket as PocketModel status = False if token and 'link' in data and data['link'] is not None\ and len(data['link']) > 0: # get the pocket data of this trigger trigger = PocketModel.objects.get(trigger_id=trigger_id) title = '' title = (data['title'] if 'title' in data else '') # convert htmlentities title = HtmlEntities(title).html_entity_decode try: self.pocket.add( url=data['link'], title=title, tags=(trigger.tag.lower())) sentence = str('pocket {} created').format(data['link']) logger.debug(sentence) status = True except Exception as e: logger.critical(e) status = False else: logger.critical("no token provided for trigger ID %s ", trigger_id) return status
def test_html_entity_decode(self): my_string = ">" my_string = HtmlEntities(my_string).html_entity_decode self.assertTrue(my_string, str)