Compare commits

..
4 Commits
Author SHA1 Message Date
retoor 8c242d1ff9 Update. 2025-10-06 08:05:47 +02:00
retoor 6c50385a06 Update. 2025-10-06 08:04:14 +02:00
retoor 30c3821d98 Update. 2025-10-06 07:48:53 +02:00
retoor 018b4e431a Initial commit. 2025-10-02 21:17:36 +02:00
4 changed files with 2 additions and 48 deletions
-2
View File
@@ -7,5 +7,3 @@ aiohttp==3.9.1
feedparser==6.0.10
websockets==12.0
trafilatura==1.6.2
vaderSentiment
+1 -7
View File
@@ -4,7 +4,6 @@ from fastapi.templating import Jinja2Templates
import dataset
import json
import aiohttp
import sentiment
import feedparser
import asyncio
from datetime import datetime
@@ -357,17 +356,15 @@ async def websocket_sync(websocket: WebSocket):
'last_synchronized': datetime.now().isoformat()
}
existing = articles_table.find_one(guid=article_data['guid'])
if not existing:
new_articles.append(article_data)
articles_count += 1
article_data['sentiment'] = json.dumps(sentiment.analyze(entry.get('description', '') or entry.get('summary', '')))
articles_table.upsert(article_data, ['guid'])
# Index the article to ChromaDB
doc_content = f"{article_data.get('title', '')}\n{article_data.get('description', '')}"
metadata = {key: str(value) for key, value in article_data.items() if key != 'content'} # Exclude large content from metadata
chroma_collection.upsert(
documents=[doc_content],
@@ -493,7 +490,6 @@ async def search_articles(
for i, doc_id in enumerate(results['ids'][0]):
res = results['metadatas'][0][i]
res['distance'] = results['distances'][0][i]
res['sentiment'] = sentiment.analyze(res.get('description', '') or res.get('content', '') or res.get('title', ''))
formatted_results.append(res)
return JSONResponse(content={"results": formatted_results})
@@ -569,8 +565,6 @@ async def newspaper_latest(request: Request):
for article in articles:
for key, value in article.items():
article[key] = str(value).strip().replace(' ', '')
article['sentiment'] = sentiment.analyze(article.get('description', '') or article.get('content', '') or res.get('title', ''))
return templates.TemplateResponse("newspaper_view.html", {
"request": request,
"newspaper": first_newspaper,
-35
View File
@@ -1,35 +0,0 @@
import json
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
def analyze_sentiment_vader(text, analyzer):
"""
Analyzes text using VADER and returns a dictionary with the results.
Args:
text (str): The text content to analyze.
analyzer (SentimentIntensityAnalyzer): An instantiated VADER analyzer.
Returns:
dict: A dictionary containing the sentiment classification, compound score,
and detailed scores (positive, neutral, negative).
"""
scores = analyzer.polarity_scores(text)
compound_score = scores['compound']
if compound_score >= 0.05:
sentiment = 'Positive'
elif compound_score <= -0.05:
sentiment = 'Negative'
else:
sentiment = 'Neutral'
return {
'sentiment': sentiment,
'score': compound_score,
'details': scores
}
vader_analyzer = SentimentIntensityAnalyzer()
def analyze(content):
return analyze_sentiment_vader(content, vader_analyzer)
-3
View File
@@ -164,7 +164,6 @@
<h2 class="article-title">
<a href="{{ article.link }}" target="_blank">{{ article.title }}</a>
</h2>
<div class="article-meta">
<span class="article-source">{{ article.feed_name }}</span>
{% if article.author %}
@@ -179,8 +178,6 @@
{% set clean_text = full_content|striptags %}
{% set display_text = clean_text[:500] if article.content else clean_text[:300] %}
{{ display_text }}{% if clean_text|length > (500 if article.content else 300) %}...{% endif %}
<div class="article-sentiment" style="display: none">Sentiment: {{ article.sentiment }}</div>
</div>
{% set words = full_content.split() %}