From fbadc3a05217e09063c2646610b5d53ecb2cfad0 Mon Sep 17 00:00:00 2001 From: andrei Date: Tue, 21 Jan 2025 20:25:28 +0500 Subject: [PATCH] ._. --- API/main.py | 41 +++++++++++++++++++- WEB/app/src/app/app.css | 50 +++++++++++++++++++++++++ WEB/app/src/app/components/news-card.js | 13 +++++++ WEB/app/src/app/page.js | 50 +++++++++++++++++++++---- 4 files changed, 145 insertions(+), 9 deletions(-) create mode 100644 WEB/app/src/app/components/news-card.js diff --git a/API/main.py b/API/main.py index 38e4b6e..9af6bd4 100644 --- a/API/main.py +++ b/API/main.py @@ -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 diff --git a/WEB/app/src/app/app.css b/WEB/app/src/app/app.css index e3708d5..1c63fdd 100644 --- a/WEB/app/src/app/app.css +++ b/WEB/app/src/app/app.css @@ -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; } \ No newline at end of file diff --git a/WEB/app/src/app/components/news-card.js b/WEB/app/src/app/components/news-card.js new file mode 100644 index 0000000..740091f --- /dev/null +++ b/WEB/app/src/app/components/news-card.js @@ -0,0 +1,13 @@ +const RSSFeed = (article, index) => { + + return ( +
+ {article.article.image && {article.article.title}} + {article.article.title} +

{article.article.description}

+

{article.article.pubDate}

+
+ ); +} + +export default RSSFeed; diff --git a/WEB/app/src/app/page.js b/WEB/app/src/app/page.js index d8beec4..131122d 100644 --- a/WEB/app/src/app/page.js +++ b/WEB/app/src/app/page.js @@ -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() {
- +

+ Календарь +

- +

+ События +

+

+ Новости +

+ +
+ {news.map((article, index) => ( + + )) + } +