示例#1
0
    def notify(self, item: FeedItem):

        if item.is_new:
            full_content = html_to_text(item.full_content)
        else:
            old = html_to_text(item.old_full_content)
            new = html_to_text(item.full_content)
            full_content = html_diff_to_markdown(html_diff2(old, new))

        link = item.link
        title = item.title
        is_new_text = ('New' if item.is_new else 'Changed')
        full_content = shorten(full_content, 8000)

        if self.message_type == "text":
            send_text_msg(self.url,
                          f"【{is_new_text}】{full_content}.... {link}")
            return
        if self.message_type == "actionCard":
            logger.info(f"正在发送 {full_content}.... {link}")

            send_action_card(self.url,
                             title=f"【{is_new_text}】 {title}",
                             text=f"【{is_new_text}】 {full_content} {link}",
                             btnOrientation=0,
                             btns=[{
                                 "title": "查看原文",
                                 "actionURL": link
                             }])
            return

        raise Exception("Unknown Message Type " + self.message_type)
示例#2
0
    def _prepared_content(self, content, message, kwargs):
        if kwargs is None:
            kwargs = {}

        if not kwargs.get("html", False) and (message and message['type'] in ('chat', 'normal')):
            # 1-1 can't have HTML.
            content = html_to_text(content)
        elif kwargs.get("html", True):
            # Hipchat is weird about spaces between tags.
            content = re.sub(r'>\s+<', '><', content)
        return content
示例#3
0
文件: plugin.py 项目: Bengt/will
    def _prepared_content(self, content, message, kwargs):
        if kwargs is None:
            kwargs = {}

        if kwargs.get("html", False) and (message and message["type"] in ("chat", "normal")):
            # 1-1 can't have HTML.
            content = html_to_text(content)
        elif kwargs.get("html", True):
            # Hipchat is weird about spaces between tags.
            content = re.sub(r">\s+<", "><", content)
        return content
示例#4
0
    def _prepared_content(self, content, message, kwargs):
        if kwargs is None:
            kwargs = {}

        if kwargs.get("html", False) and (message and message['type']
                                          in ('chat', 'normal')):
            # 1-1 can't have HTML.
            content = html_to_text(content)
        elif kwargs.get("html", True):
            # Hipchat is weird about spaces between tags.
            content = re.sub(r'>\s+<', '><', content)
        return content
示例#5
0
def extract_text(xpath_results):
    if type(xpath_results) == list:
        # it's list of result : concat everything using recursive call
        if not xpath_results:
            raise Exception('Empty url resultset')
        result = ''
        for e in xpath_results:
            result = result + extract_text(e)
        return result
    elif type(xpath_results) in [_ElementStringResult, _ElementUnicodeResult]:
        # it's a string
        return ''.join(xpath_results)
    else:
        # it's a element
        return html_to_text(xpath_results.text_content())
示例#6
0
def extract_text(xpath_results):
    if type(xpath_results) == list:
        # it's list of result : concat everything using recursive call
        if not xpath_results:
            raise Exception('Empty url resultset')
        result = ''
        for e in xpath_results:
            result = result + extract_text(e)
        return result
    elif type(xpath_results) in [_ElementStringResult, _ElementUnicodeResult]:
        # it's a string
        return ''.join(xpath_results)
    else:
        # it's a element
        return html_to_text(xpath_results.text_content())
 def prepare_description(self,obj):
     if obj.description:
         return utils.html_to_text( obj.description )
     return None
示例#8
0
 def sanitize(self, var, preserve=None):
     sanitized = html_to_text(var).replace('http://',
                                           '').replace('https://', '')
     if preserve != 'parent_dir':
         sanitized.replace('../', '')
     return sanitized
示例#9
0
 def on_send_push_button_clicked(self):
     message = html_to_text(self.textEdit.toHtml())
     self.send_package(message.encode("utf-8"), self.destination_port)
     self.append_text_browser(message, "Me")
     self.textEdit.setText("")
示例#10
0
 def sanitize(self, var, preserve = None):
     sanitized = html_to_text(var).replace('http://', '').replace('https://', '')
     if preserve != 'parent_dir':
         sanitized.replace('../', '')
     return sanitized