Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
import os
|
|
|
2 |
from flask import Flask, render_template, request, Response, jsonify
|
3 |
from rss_processor import fetch_rss_feeds, process_and_store_articles, vector_db
|
4 |
import logging
|
5 |
import time
|
6 |
-
from threading import Thread
|
7 |
import hashlib
|
8 |
|
9 |
app = Flask(__name__)
|
@@ -12,22 +12,10 @@ app = Flask(__name__)
|
|
12 |
logging.basicConfig(level=logging.INFO)
|
13 |
logger = logging.getLogger(__name__)
|
14 |
|
15 |
-
def load_feeds_in_background():
|
16 |
-
logger.info("Starting to fetch and process RSS feeds in background")
|
17 |
-
start_time = time.time()
|
18 |
-
articles = fetch_rss_feeds()
|
19 |
-
logger.info(f"Fetched {len(articles)} articles")
|
20 |
-
process_and_store_articles(articles)
|
21 |
-
logger.info("Articles processed and stored")
|
22 |
-
end_time = time.time()
|
23 |
-
logger.info(f"RSS feed loading took {end_time - start_time:.2f} seconds")
|
24 |
-
|
25 |
@app.route('/')
|
26 |
def loading():
|
27 |
-
# Start loading feeds in a
|
28 |
-
|
29 |
-
thread.daemon = True
|
30 |
-
thread.start()
|
31 |
return render_template("loading.html")
|
32 |
|
33 |
@app.route('/check_feeds', methods=['GET'])
|
@@ -45,7 +33,8 @@ def check_feeds():
|
|
45 |
|
46 |
@app.route('/index', methods=['GET'])
|
47 |
def index():
|
48 |
-
|
|
|
49 |
# Use a set to ensure unique articles by title, link, and description hash
|
50 |
unique_articles = {}
|
51 |
for doc in stored_docs:
|
@@ -97,7 +86,7 @@ def index():
|
|
97 |
categorized_articles[cat] = []
|
98 |
categorized_articles[cat].append(article)
|
99 |
|
100 |
-
return render_template("index.html", categorized_articles=categorized_articles)
|
101 |
|
102 |
if __name__ == "__main__":
|
103 |
-
app.run(host="0.0.0.0", port=
|
|
|
1 |
import os
|
2 |
+
import subprocess
|
3 |
from flask import Flask, render_template, request, Response, jsonify
|
4 |
from rss_processor import fetch_rss_feeds, process_and_store_articles, vector_db
|
5 |
import logging
|
6 |
import time
|
|
|
7 |
import hashlib
|
8 |
|
9 |
app = Flask(__name__)
|
|
|
12 |
logging.basicConfig(level=logging.INFO)
|
13 |
logger = logging.getLogger(__name__)
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
@app.route('/')
|
16 |
def loading():
|
17 |
+
# Start loading feeds in a subprocess
|
18 |
+
subprocess.Popen(["python", "rss_processor.py", "load_feeds"])
|
|
|
|
|
19 |
return render_template("loading.html")
|
20 |
|
21 |
@app.route('/check_feeds', methods=['GET'])
|
|
|
33 |
|
34 |
@app.route('/index', methods=['GET'])
|
35 |
def index():
|
36 |
+
# Show existing articles while new feeds load in background
|
37 |
+
stored_docs = vector_db.similarity_search("news", k=1000) # Show all available articles
|
38 |
# Use a set to ensure unique articles by title, link, and description hash
|
39 |
unique_articles = {}
|
40 |
for doc in stored_docs:
|
|
|
86 |
categorized_articles[cat] = []
|
87 |
categorized_articles[cat].append(article)
|
88 |
|
89 |
+
return render_template("index.html", categorized_articles=categorized_articles, loading_new_feeds=True)
|
90 |
|
91 |
if __name__ == "__main__":
|
92 |
+
app.run(debug=True, host="0.0.0.0", port=5000)
|