This commit is contained in:
Андрей Дувакин 2025-01-21 20:25:28 +05:00
parent 492807f8a2
commit fbadc3a052
4 changed files with 145 additions and 9 deletions

View File

@ -1,9 +1,11 @@
import datetime
import pprint
import random
import feedparser
import jwt
from data.connect import init_db, connect, User, Document, DocumentCategory, Comment
from data.connect import init_db, connect, User, Document, DocumentCategory, Comment, Event
from flask import Flask, Response, request, jsonify
from flask_cors import CORS
@ -288,6 +290,43 @@ def get_employee_list():
}
)
return resp
@app.route("/rss")
def get_rss_feed():
feed = feedparser.parse('https://naukatv.ru/rss')
news_items = []
for entry in feed.entries:
news_items.append({
"title": entry.title,
"link": entry.link,
"description": entry.get("description", "Без описания"),
"pubDate": entry.get("published", "Нет даты"),
"image": entry.links[1].href,
})
return news_items
@app.route('/events')
def get_events():
resp = []
with connect() as session:
events = session.query(Event).all()
users = session.query(User).all()
for event in events:
user = random.choice(users)
resp.append({
'title': event.title,
'date': str(event.datetime_event.date()),
'author': f'{user.last_name} {user.first_name}',
'description': event.title,
})
return resp

View File

@ -67,4 +67,54 @@
display: flex;
flex-direction: row;
justify-content: space-between;
}
.content {
display: flex;
flex-direction: row;
}
.calendar-and-events {
width: 30%;
}
.news {
width: 70%;
}
.news-block {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 10px;
}
.news-item {
width: 450px;
height: 400px;
background-color: #2f9836;
display: flex;
flex-direction: column;
padding: 1vw;
color: white;
}
.image-rss {
width: 107%;
margin-top: -1vw;
margin-left: -1vw;
margin-right: -1vw;
}
.calendar {
margin: 2vw;
border: 1px solid black;
height: 25vw;
}
.events {
margin: 2vw;
border: 1px solid black;
}

View File

@ -0,0 +1,13 @@
const RSSFeed = (article, index) => {
return (
<div className="news-item">
{article.article.image && <img src={article.article.image} alt={article.article.title} className="image-rss" />}
<strong>{article.article.title}</strong>
<p>{article.article.description}</p>
<p><i>{article.article.pubDate}</i></p>
</div>
);
}
export default RSSFeed;

View File

@ -4,13 +4,27 @@ import './app.css';
import Header from './components/header.js';
import EmployeeCard from './components/employee-card.js';
import { useEffect, useState } from 'react';
import RSSFeed from './components/news-card.js';
export default function Home() {
const [employees, setEmployees] = useState([]);
const [news, setNews] = useState([]);
useEffect(() => {
fetchEmployees();
fetchRSS();
const interval = setInterval(
() => {
fetchEmployees();
fetchRSS();
}, 5000
)
return () => {
clearInterval(interval);
}
}, []);
const fetchEmployees = async () => {
@ -27,13 +41,19 @@ export default function Home() {
}
}
const b = (digit) => {
}
const fetchRSS = async () => {
try {
const response = await fetch("http://127.0.0.1:5000/rss");
const a = [1, 2, 3, 4];
a.map(
b
)
if (response.ok) {
const json_data = await response.json();
setNews(json_data);
}
} catch (error) {
console.error("Ошибка загрузки RSS:", error);
}
};
return (
<>
@ -62,16 +82,30 @@ export default function Home() {
<div className="calendar-and-events">
<div className="calendar">
<h1>
Календарь
</h1>
</div>
<div className="events">
<h1>
События
</h1>
</div>
</div>
<div className="news">
<h1>
Новости
</h1>
<div className='news-block'>
{news.map((article, index) => (
<RSSFeed key={index} article={article} index={index}/>
))
}
</div>
</div>