feedleware/feedleware/openalex/feed.py

42 lines
1.1 KiB
Python

from ..feedformatter import Feed
from .openalex import APIClient
def construct_rss(client: APIClient, name: str) -> str:
"""
Build a RSS stream for an academic author.
:param client: OpenAlex API client
:param name: author display name
:returns: RSS stream
:raises HTTPException: if one of the requests fail
"""
author_list = client.author(name)
works = client.works(author_list)
feed = Feed()
# Set the feed/author level properties
feed.feed["title"] = name
feed.feed["link"] = "https://example.org"
feed.feed["description"] = f"Latest works of {name} from the OpenAlex dataset."
feed.feed["author"] = "Feedleware"
feed.feed["ttl"] = "30"
for work in works:
feed.items.append({
"guid": work["id"],
"title": work["title"],
"link": work["url"],
"description": (
"; ".join(work["authors"])
+ "<br>"
+ work["source"]
+ "<br><br>"
+ work["description"]
),
"pubDate": work["date"].timetuple(),
})
return feed.format_rss2_string()