Spaces:
Sleeping
Sleeping
Upload 4 files
Browse files- Dockerfile.txt +22 -0
- app.py +67 -0
- requirements.txt +2 -0
- templates/index.html +18 -0
Dockerfile.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Use official Python runtime as base image
|
| 2 |
+
FROM python:3.10-slim
|
| 3 |
+
|
| 4 |
+
# Set environment variables
|
| 5 |
+
ENV PYTHONDONTWRITEBYTECODE=1
|
| 6 |
+
ENV PYTHONUNBUFFERED=1
|
| 7 |
+
|
| 8 |
+
# Set working directory
|
| 9 |
+
WORKDIR /code
|
| 10 |
+
|
| 11 |
+
# Install dependencies
|
| 12 |
+
COPY requirements.txt /code/
|
| 13 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 14 |
+
|
| 15 |
+
# Copy app files
|
| 16 |
+
COPY . /code/
|
| 17 |
+
|
| 18 |
+
# Hugging Face Spaces requirement: expose port 7860 (we’ll still run on 7860 even if your app.py says 5006)
|
| 19 |
+
ENV PORT 7860
|
| 20 |
+
|
| 21 |
+
# Run app
|
| 22 |
+
CMD ["python", "app.py"]
|
app.py
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Flask, render_template
|
| 2 |
+
import feedparser
|
| 3 |
+
|
| 4 |
+
app = Flask(__name__)
|
| 5 |
+
|
| 6 |
+
# Expanded RSS news feeds – U.S. and international
|
| 7 |
+
rss_urls = [
|
| 8 |
+
# US National
|
| 9 |
+
"https://rss.nytimes.com/services/xml/rss/nyt/HomePage.xml",
|
| 10 |
+
"https://rss.nytimes.com/services/xml/rss/nyt/World.xml",
|
| 11 |
+
"https://rss.nytimes.com/services/xml/rss/nyt/US.xml",
|
| 12 |
+
"https://feeds.npr.org/1001/rss.xml",
|
| 13 |
+
"https://www.cbsnews.com/latest/rss/main",
|
| 14 |
+
"https://abcnews.go.com/abcnews/topstories",
|
| 15 |
+
"https://www.nbcnews.com/id/3032091/device/rss/rss.xml",
|
| 16 |
+
"https://rss.cnn.com/rss/edition.rss",
|
| 17 |
+
"https://feeds.foxnews.com/foxnews/latest",
|
| 18 |
+
"https://www.wsj.com/xml/rss/3_7085.xml", # WSJ World
|
| 19 |
+
"https://www.washingtontimes.com/rss/headlines/news/",
|
| 20 |
+
"https://www.latimes.com/local/rss2.0.xml",
|
| 21 |
+
"https://www.politico.com/rss/politics08.xml",
|
| 22 |
+
"https://www.theatlantic.com/feed/all/",
|
| 23 |
+
|
| 24 |
+
# International
|
| 25 |
+
"https://www.theguardian.com/world/rss",
|
| 26 |
+
"https://www.theguardian.com/us-news/rss",
|
| 27 |
+
"https://www.reutersagency.com/feed/?best-sectors=general-news&post_type=best",
|
| 28 |
+
"https://feeds.bbci.co.uk/news/world/rss.xml",
|
| 29 |
+
"https://feeds.bbci.co.uk/news/rss.xml",
|
| 30 |
+
"https://globalnews.ca/feed/",
|
| 31 |
+
"https://english.alarabiya.net/.mrss/en.xml",
|
| 32 |
+
"https://www.france24.com/en/rss",
|
| 33 |
+
"https://www.dw.com/en/top-stories/s-9097",
|
| 34 |
+
"https://www.hindustantimes.com/rss/topnews/rssfeed.xml",
|
| 35 |
+
"https://timesofindia.indiatimes.com/rssfeedstopstories.cms",
|
| 36 |
+
"https://japantoday.com/category/national/rss",
|
| 37 |
+
"https://www.smh.com.au/rss/feed.xml",
|
| 38 |
+
"https://www.abc.net.au/news/feed/51120/rss.xml",
|
| 39 |
+
"https://www.aljazeera.com/xml/rss/all.xml",
|
| 40 |
+
"https://www.scmp.com/rss/91/feed", # South China Morning Post
|
| 41 |
+
]
|
| 42 |
+
|
| 43 |
+
# Fetch RSS feed
|
| 44 |
+
def get_rss_articles():
|
| 45 |
+
articles = []
|
| 46 |
+
|
| 47 |
+
for url in rss_urls:
|
| 48 |
+
feed = feedparser.parse(url)
|
| 49 |
+
for entry in feed.entries:
|
| 50 |
+
articles.append({
|
| 51 |
+
"title": entry.title,
|
| 52 |
+
"link": entry.link,
|
| 53 |
+
"summary": entry.get("summary", ""),
|
| 54 |
+
"published": entry.get("published", ""),
|
| 55 |
+
"source": url
|
| 56 |
+
})
|
| 57 |
+
|
| 58 |
+
return articles
|
| 59 |
+
|
| 60 |
+
# Routes
|
| 61 |
+
@app.route("/")
|
| 62 |
+
def index():
|
| 63 |
+
articles = get_rss_articles()
|
| 64 |
+
return render_template("index.html", articles=articles)
|
| 65 |
+
|
| 66 |
+
if __name__ == "__main__":
|
| 67 |
+
app.run(debug=True, port=5006)
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
flask
|
| 2 |
+
feedparser
|
templates/index.html
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html>
|
| 3 |
+
<head>
|
| 4 |
+
<title>News + X Aggregator</title>
|
| 5 |
+
</head>
|
| 6 |
+
<body>
|
| 7 |
+
<h1>Latest News + X Posts</h1>
|
| 8 |
+
<ul>
|
| 9 |
+
{% for item in articles %}
|
| 10 |
+
<li style="margin-bottom: 20px;">
|
| 11 |
+
<strong>{{ item.title }}</strong><br/>
|
| 12 |
+
<small>{{ item.published }} — {{ item.source }}</small><br/>
|
| 13 |
+
<a href="{{ item.link }}" target="_blank">Read more</a>
|
| 14 |
+
</li>
|
| 15 |
+
{% endfor %}
|
| 16 |
+
</ul>
|
| 17 |
+
</body>
|
| 18 |
+
</html>
|