1
Fork 0
lwn-feed-proxy/main.py
Jake Howard 62c2f929d6
Remove cache
For this use case, it's unnecessary
2024-10-22 21:54:29 +01:00

35 lines
899 B
Python

from bs4 import BeautifulSoup
from httpx import AsyncClient
from starlette.applications import Starlette
from starlette.requests import Request
from starlette.responses import Response
from starlette.routing import Route
client = AsyncClient()
FEED_URL = "https://lwn.net/headlines/rss"
async def index(request: Request) -> Response:
feed_response = await client.get(FEED_URL)
raw_feed = await feed_response.aread()
feed = BeautifulSoup(raw_feed, "xml")
for item in feed.find_all("item"):
title = item.find("title").text
# Hide entries behind a paywall
if title.startswith("[$]"):
item.extract()
return Response(content=feed.encode(), media_type="application/xml")
async def health(request: Request) -> Response:
return Response()
app = Starlette(
routes=[Route("/", endpoint=index), Route("/.health/", endpoint=health)]
)