import datetime
from feedgenerator import Rss201rev2Feed
import requests
from bs4 import BeautifulSoup

# 1. Initialize the feed
feed = Rss201rev2Feed(
    title="Internetcable news",
    link="http://internetcable.eu.org",
    description="Latest news",
    language="en",
)

# 2. Scrape the website
url = "https://steamcommunity.com/id/jamieb452"
response = requests.get(url)
soup = BeautifulSoup(response.text, "html.parser")

# 3. Extract items (e.g., Hacker News headlines)
for item in soup.find_all("tr", class_="athing"):
    title = item.find("span", class_="titleline").text
    link = item.find("span", class_="titleline").find("a")["href"]

    feed.add_item(
        title=title,
        link=link,
        description="Latest news",
        pubdate=datetime.datetime.now(),
    )

# 4. Write to an XML file
with open("rss.xml", "w", encoding="utf-8") as f:
    feed.write(f, "utf-8")
