def result(self): url = self.url.data url = url[:url.find('?')] return Link( title=self.title.data, slug=make_slug(self.title.data), text=self.text.data, url=url, )
def get_links(self): """ Get new links :return: """ d = feedparser.parse(self.url) if d["bozo"] == 1: raise NameError res = [] for entry in d["entries"]: # get the link text text = remove_html_tags(entry["summary"]) if "summary" in entry else "" if len(text) > 300: if "content" in entry: for e in entry["content"]: if "value" in e and len(e["value"]) < 300: text = remove_html_tags(e["value"]) # if the text is still longer trim by sentences to 300 characters max if len(text) > 300: idx = text.rfind(". ", 0, 300) text = text[: idx + 1] # TODO img? if "links" in entry: for link in entry["links"]: if link["type"] == "image/jpeg": print(link) # title title = entry["title"] # if the title is too long trim it by words to 128 chars max # we allow admins to edit autoposted links, so they can fix badly trimmed titles later if len(title) > 128: idx = title.rfind(" ", 0, 128) title = title[:idx] res.append( { "title": title, "slug": make_slug(title), "text": text, "url": entry["link"], "feed_id": self.feed.id, } ) return res
def result(self) -> Feed: return Feed( name=self.name.data, description=self.description.data, slug=make_slug(self.name.data), )