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)
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
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
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
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
def sanitize(self, var, preserve=None): sanitized = html_to_text(var).replace('http://', '').replace('https://', '') if preserve != 'parent_dir': sanitized.replace('../', '') return sanitized
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("")
def sanitize(self, var, preserve = None): sanitized = html_to_text(var).replace('http://', '').replace('https://', '') if preserve != 'parent_dir': sanitized.replace('../', '') return sanitized