def build_entry(article, blog_uri):
    title = article["title"]["rendered"]
    slug = article["slug"]
    author = article["_embedded"]["author"][0]
    description = article["excerpt"]["rendered"]
    content = article["content"]["rendered"]
    published = f'{article["date_gmt"]} GMT'
    updated = f'{article["modified_gmt"]} GMT'
    link = f"{blog_uri}/{slug}"

    categories = []

    if "wp:term" in article["_embedded"]:
        for category in article["_embedded"]["wp:term"][1]:
            categories.append(
                dict(term=category["slug"], label=category["name"]))

    entry = FeedEntry()
    entry.title(title)
    entry.description(description)
    entry.content(content)
    entry.author(name=author["name"], email=author["name"])
    entry.link(href=link)
    entry.category(categories)
    entry.published(published)
    entry.updated(updated)

    return entry
Beispiel #2
0
    def as_feed_entry(self) -> FeedEntry:
        result = FeedEntry()
        result.id(self.id)
        result.link(href=self.link)
        result.content(self.content)
        result.title(self.title())
        result.published(self.published)
        result.enclosure(self.get_file_url(), 0, 'audio/mpeg')

        return result
Beispiel #3
0
async def create_entry(article):
    heading = article.select_one(".main-article-heading-box")
    entry = FeedEntry()
    entry.id(heading.select_one("a").get("href"))
    entry.link(href=heading.select_one("a").get("href"))
    entry.title(" / ".join(s.text for s in heading.select("span")))
    name = article.select_one(".main-article-author-box a").text.strip()
    entry.author({"name": name})
    entry.summary(article.select_one(".perex-lim").text.strip())
    date = article.select_one(".main-article-author-box small").text.strip()
    date = datetime.strptime(date, "%d.%m.%Y, %H:%M")
    entry.published(date.replace(tzinfo=timezone.utc))
    return entry
Beispiel #4
0
def rss_entries(links, feed=None):
    entries = []
    for link in links:
        fe = FeedEntry()
        fe.title(link.title)
        fe.content(link.text)
        fe.summary("Post by {} in {}.".format(
            link.user.name, feed.name if feed else link.feed.name))
        fe.link(href=link.url)
        fe.published(link.created_at)
        fe.comments(link.url)
        fe.author(name=link.user.name)
        entries.append(fe)
    return entries
Beispiel #5
0
def users_logs_feed(context, request):
    entries = []
    for log in (request.db.query(Log).filter(
            Log.creator_id == context.id).order_by(
                Log.last_modified.desc()).limit(25).all()):
        entry = FeedEntry()
        entry.id(str(log.id))
        entry.title(log.name)
        entry.content(log.summary or "No summary.")
        entry.published(utc.localize(log.created))
        entries.append(entry)

    return {
        "title": "%s's logs" % context.username,
        "entries": entries,
    }
Beispiel #6
0
    def _build_feed(
        self, blog_url, feed_url, feed_title, feed_description, articles
    ):
        """
        Build the content for the feed
        :blog_url: string blog url
        :feed_url: string url
        :feed_title: string title
        :feed_description: string description
        :param articles: Articles to create feed from
        """
        feed = FeedGenerator()
        feed.generator("Python Feedgen")
        feed.title(feed_title)
        feed.description(feed_description)
        feed.link(href=feed_url, rel="self")

        for article in articles:
            title = article["title"]["rendered"]
            slug = article["slug"]
            author = article["_embedded"]["author"][0]
            description = article["excerpt"]["rendered"]
            content = article["content"]["rendered"]
            published = f'{article["date_gmt"]} GMT'
            updated = f'{article["modified_gmt"]} GMT'
            link = f"{blog_url}/{slug}"

            categories = []

            if "wp:term" in article["_embedded"]:
                for category in article["_embedded"]["wp:term"][1]:
                    categories.append(
                        dict(term=category["slug"], label=category["name"])
                    )

            entry = FeedEntry()
            entry.title(title)
            entry.description(description)
            entry.content(content)
            entry.author(name=author["name"], email=author["name"])
            entry.link(href=link)
            entry.category(categories)
            entry.published(published)
            entry.updated(updated)
            feed.add_entry(entry, order="append")

        return feed
Beispiel #7
0
    def feed_entry(notice, url_root):
        _id = notice.id
        title = f"{_id}: {notice.title}"
        description = notice.details
        published = notice.published
        notice_path = flask.url_for(".notice", notice_id=notice.id).lstrip("/")
        link = f"{url_root}{notice_path}"

        entry = FeedEntry()
        entry.id(link)
        entry.title(title)
        entry.description(description)
        entry.link(href=link)
        entry.published(f"{published} UTC")
        entry.author({"name": "Ubuntu Security Team"})

        return entry
Beispiel #8
0
def make_entry(f, yargs, html):
    """Construct a (datetime, FeedEntry)..."""
    from feedgen.entry import FeedEntry

    uri = yargs.feed_link + (str(f.parent) + "/").replace("./", "") + str(
        f.stem) + ".html"
    print(uri)

    title = str(f.stem).replace('_', ' ').title()
    updated = datetime.datetime.fromtimestamp(os.path.getmtime(f),
                                              datetime.timezone.utc)

    # anything YAML based to get better metadata goes here too, I suppose

    y = getyaml(f)
    print(y)

    if "title" in y:
        title = y["title"]

    e = FeedEntry()
    e.link(href=uri)
    e.id(uri)
    e.content(html)
    e.updated(updated)
    e.title(title)
    if "date" in y:
        d = y["date"]  # anything other than the below is super messy
        e.published(
            datetime.datetime(d.year,
                              d.month,
                              d.day,
                              tzinfo=datetime.timezone.utc))

    if "keywords" in y:
        for k in y["keywords"]:
            e.category(category={'term': k, 'scheme': '', 'label': k})

    if "subtitle" in y:
        # close enough
        e.summary(y["subtitle"])
    if "abstract" in y:
        # but this is even better, if it exists
        e.summary(y["abstract"])

    return (updated, e)
Beispiel #9
0
def users_favorites_feed(context, request):
    entries = []
    for favorite in (request.db.query(Favorite).filter(
            Favorite.user_id == context.id).order_by(
                Favorite.created.desc()).options(
                    joinedload(Favorite.log).joinedload(
                        Log.creator)).limit(25).all()):
        entry = FeedEntry()
        entry.id(str(favorite.log.id))
        entry.title("%s favorited %s." % (context.username, favorite.log.name))
        entry.content(favorite.log.summary or "No summary.")
        entry.published(utc.localize(favorite.created))
        entries.append(entry)

    return {
        "title": "%s's favorites" % context.username,
        "entries": entries,
    }
Beispiel #10
0
def users_logs_feed(context, request):
    entries = []
    for log in (
        request.db.query(Log)
        .filter(Log.creator_id == context.id)
        .order_by(Log.last_modified.desc())
        .limit(25).all()
    ):
        entry = FeedEntry()
        entry.id(str(log.id))
        entry.title(log.name)
        entry.content(log.summary or "No summary.")
        entry.published(utc.localize(log.created))
        entries.append(entry)

    return {
        "title": "%s's logs" % context.username,
        "entries": entries,
    }
Beispiel #11
0
def users_subscriptions_feed(context, request):
    entries = []
    for subscription in (request.db.query(LogSubscription).filter(
            LogSubscription.user_id == context.id).order_by(
                LogSubscription.created.desc()).options(
                    joinedload(LogSubscription.log).joinedload(
                        Log.creator)).limit(25).all()):
        entry = FeedEntry()
        entry.id(str(subscription.log.id))
        entry.title("%s subscribed to %s." %
                    (context.username, subscription.log.name))
        entry.content(subscription.log.summary or "No summary.")
        entry.published(utc.localize(subscription.created))
        entries.append(entry)

    return {
        "title": "%s's subscriptions" % context.username,
        "entries": entries,
    }
Beispiel #12
0
def users_favorites_feed(context, request):
    entries = []
    for favorite in (
        request.db.query(Favorite)
        .filter(Favorite.user_id == context.id)
        .order_by(Favorite.created.desc())
        .options(joinedload(Favorite.log).joinedload(Log.creator))
        .limit(25).all()
    ):
        entry = FeedEntry()
        entry.id(str(favorite.log.id))
        entry.title("%s favorited %s." % (context.username, favorite.log.name))
        entry.content(favorite.log.summary or "No summary.")
        entry.published(utc.localize(favorite.created))
        entries.append(entry)

    return {
        "title": "%s's favorites" % context.username,
        "entries": entries,
    }
Beispiel #13
0
def users_subscriptions_feed(context, request):
    entries = []
    for subscription in (
        request.db.query(LogSubscription)
        .filter(LogSubscription.user_id == context.id)
        .order_by(LogSubscription.created.desc())
        .options(joinedload(LogSubscription.log).joinedload(Log.creator))
        .limit(25).all()
    ):
        entry = FeedEntry()
        entry.id(str(subscription.log.id))
        entry.title("%s subscribed to %s." % (context.username, subscription.log.name))
        entry.content(subscription.log.summary or "No summary.")
        entry.published(utc.localize(subscription.created))
        entries.append(entry)

    return {
        "title": "%s's subscriptions" % context.username,
        "entries": entries,
    }