コード例 #1
0
def build_feed(posts: List[Post], feed_metadata: FeedMetadata) -> Feed:
    feed_items: List[Item] = []

    for post in posts:
        if not post.metadata.hidden:
            feed_items.append(
                build_item(post, feed_metadata.base_url,
                           feed_metadata.base_image_url))

    feed = Feed(
        title=feed_metadata.title,
        link=feed_metadata.link,
        description=feed_metadata.description,
        language=feed_metadata.language,
        lastBuildDate=datetime.now(),
        items=feed_items,
        extensions=[ContentExtension()],
    )
    feed.docs = None
    feed.generator = None

    return feed
コード例 #2
0
    def get_xml(self: Serializer, response: Response) -> Tuple[str, int]:
        """
        Serialize the provided response data into RSS, version 2.0.

        Parameters
        ----------
        response : Response
            The search response data to be serialized.

        Returns
        -------
        data : str
            The serialized XML results.
        status
            The HTTP status code for the operation.

        """
        # Get the archive info from the first hit.  Is this OK?
        archive = response.hits[0]["primary_classification"]["archive"]
        archive_id = archive["id"]
        archive_name = archive["name"]
        feed = Feed(
            title=f"{archive_id} updates on arXiv.org",
            link="http://arxiv.org/",
            description=f"{archive_name} ({archive_id}) updates on the arXiv.org e-print archive",
            language="en-us",
            pubDate=datetime.now(),
            lastBuildDate=datetime.now(),
            managingEditor="*****@*****.**"
        )

        # Remove two elements added by the Rfeed package
        feed.generator = None
        feed.docs = None

        # Add extensions that will show up as attributes of the rss element
        feed.extensions.append(Content())
        feed.extensions.append(Taxonomy())
        feed.extensions.append(Syndication())
        feed.extensions.append(Admin())
        feed.image = Image(url="http://arxiv.org/icons/sfx.gif",
                           title="arXiv.org", link="http://arxiv.org")

        # Add each search result "hit" to the feed
        for hit in response:
            # Add links for each author and the abstract to the description element
            description = "<p>Authors: "
            first = True
            for author in hit['authors']:
                if first:
                    first = False
                else:
                    description += ", "
                name = f"{author['last_name']},+{author['initials'].replace(' ', '+')}"
                description += f"<a href='http://arxiv.org/search/?query={name}&searchtype=author'>"
                description += f"{author['full_name']}</a>"
            description += f"</p><p>{hit['abstract']}</p>"

            # Create the item element for the "hit"
            item = Item(
                title=hit['title'],
                link=url_for("abs_by_id", paper_id=hit['paper_id']),
                # link=f"http://arxiv.org/abs/{hit['paper_id']}",
                description=description,
                guid=Guid(f"oai:arXiv.org:{hit['paper_id']}", isPermaLink=False)
            )
            feed.items.append(item)

        # Print and return the feed content
        data = feed.rss()
        status_code = status.HTTP_200_OK
        return data, status_code