def get_custom_text_lines(self): textbuffer = self.glade.get_widget("textview_custom_text").get_buffer() lines = [] text = textbuffer.get_text(textbuffer.get_start_iter(), textbuffer.get_end_iter()) text = string_to_unicode(text) for line in text.splitlines(): lines.append(line.strip()) return lines
def update_rssfeeds_dict_matching(self, rssfeed_parsed, options): """rssfeed_parsed: Dictionary returned by get_rssfeed_parsed_dict options, a dictionary with the following keys: * "regex_include": str * "regex_exclude": str * "regex_include_ignorecase": bool * "regex_exclude_ignorecase": bool Updates the items in rssfeed_parsed Return: a dictionary of the matching items only. """ # regex and title are converted from utf-8 unicode to ascii strings before matching # This is because the indexes returned by span must be the byte index of the text, # because Pango attributes takes the byte index, and not character index. matching_items = {} p_include = p_exclude = None message = None # Remove old custom lines for key in rssfeed_parsed.keys(): if rssfeed_parsed[key]["link"] is None: del rssfeed_parsed[key] if options.has_key("custom_text_lines") and options["custom_text_lines"]: if not type(options["custom_text_lines"]) is list: self.log.warn("type of custom_text_lines' must be list") else: for l in options["custom_text_lines"]: key = common.get_new_dict_key(rssfeed_parsed, string_key=False) rssfeed_parsed[key] = self._new_rssfeeds_dict_item(l, key=key) if options["regex_include"] is not None and options["regex_include"] != "": flags = re.IGNORECASE if options["regex_include_ignorecase"] else 0 try: regex = common.string_to_unicode(options["regex_include"]).encode("utf-8") p_include = re.compile(regex, flags) except Exception, e: #traceback.print_exc(e) self.log.warn("Regex compile error:" + str(e)) message = "Regex: %s" % e p_include = None
def update_rssfeeds_dict_matching(self, rssfeed_parsed, options): """rssfeed_parsed: Dictionary returned by get_rssfeed_parsed_dict options, a dictionary with the following keys: * "regex_include": str * "regex_exclude": str * "regex_include_ignorecase": bool * "regex_exclude_ignorecase": bool Updates the items in rssfeed_parsed Return: a dictionary of the matching items only. """ # regex and title are converted from utf-8 unicode to ascii strings before matching # This is because the indexes returned by span must be the byte index of the text, # because Pango attributes takes the byte index, and not character index. matching_items = {} p_include = p_exclude = None message = None # Remove old custom lines for key in rssfeed_parsed.keys(): if rssfeed_parsed[key]["link"] is None: del rssfeed_parsed[key] if "custom_text_lines" in options and options["custom_text_lines"]: if not type(options["custom_text_lines"]) is list: self.log.warn("type of custom_text_lines' must be list") else: for l in options["custom_text_lines"]: key = common.get_new_dict_key(rssfeed_parsed, string_key=False) rssfeed_parsed[key] = self._new_rssfeeds_dict_item(l, key=key) if options["regex_include"] is not None and options["regex_include"] != "": flags = re.IGNORECASE if options["regex_include_ignorecase"] else 0 try: regex = common.string_to_unicode(options["regex_include"]).encode("utf-8") p_include = re.compile(regex, flags) except Exception, e: self.log.warn("Regex compile error:" + str(e)) message = "Regex: %s" % e p_include = None
if options["regex_include"] is not None and options["regex_include"] != "": flags = re.IGNORECASE if options["regex_include_ignorecase"] else 0 try: regex = common.string_to_unicode(options["regex_include"]).encode("utf-8") p_include = re.compile(regex, flags) except Exception, e: #traceback.print_exc(e) self.log.warn("Regex compile error:" + str(e)) message = "Regex: %s" % e p_include = None if options["regex_exclude"] is not None and options["regex_exclude"] != "": flags = re.IGNORECASE if options["regex_exclude_ignorecase"] else 0 try: regex = common.string_to_unicode(options["regex_exclude"]).encode("utf-8") p_exclude = re.compile(regex, flags) except Exception, e: #traceback.print_exc(e) self.log.warn("Regex compile error:" + str(e)) message = "Regex: %s" % e p_exclude = None for key in rssfeed_parsed.keys(): item = rssfeed_parsed[key] title = item["title"].encode("utf-8") if item.has_key("regex_exclude_match"): del item["regex_exclude_match"] if item.has_key("regex_include_match"): del item["regex_include_match"]
rssfeed_parsed[key] = self._new_rssfeeds_dict_item(l, key=key) if options["regex_include"] is not None and options["regex_include"] != "": flags = re.IGNORECASE if options["regex_include_ignorecase"] else 0 try: regex = common.string_to_unicode(options["regex_include"]).encode("utf-8") p_include = re.compile(regex, flags) except Exception, e: self.log.warn("Regex compile error:" + str(e)) message = "Regex: %s" % e p_include = None if options["regex_exclude"] is not None and options["regex_exclude"] != "": flags = re.IGNORECASE if options["regex_exclude_ignorecase"] else 0 try: regex = common.string_to_unicode(options["regex_exclude"]).encode("utf-8") p_exclude = re.compile(regex, flags) except Exception, e: self.log.warn("Regex compile error:" + str(e)) message = "Regex: %s" % e p_exclude = None for key in rssfeed_parsed.keys(): item = rssfeed_parsed[key] title = item["title"].encode("utf-8") if "regex_exclude_match" in item: del item["regex_exclude_match"] if "regex_include_match" in item: del item["regex_include_match"]