From 2dcc7735e996f95d8062c89df75c32bfcaa1aea9 Mon Sep 17 00:00:00 2001 From: Kacper Latuszewski Date: Tue, 18 Feb 2020 20:06:39 +0100 Subject: [PATCH 01/10] Getting date --- flask_app/get_data.py | 13 +++++++++++++ flask_app/main.py | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/flask_app/get_data.py b/flask_app/get_data.py index 05c4b654..16c6d199 100644 --- a/flask_app/get_data.py +++ b/flask_app/get_data.py @@ -29,3 +29,16 @@ def main(): else: replacements[teacher].append(lesson_info) return replacements + +def date(): + with codecs.open( + "mocks/template.html", "r", "utf-8" + ) as f: # Zastępstwa.html in main folder + soup = BeautifulSoup(f.read(), "html.parser") + + h2 = soup.find_all("h2") + data = h2[0] + date = str(data.text).split(' ')[1] + + return date + \ No newline at end of file diff --git a/flask_app/main.py b/flask_app/main.py index 2c4951b6..5638e235 100644 --- a/flask_app/main.py +++ b/flask_app/main.py @@ -37,6 +37,10 @@ def get_all(): all_substitutions += sorted(teacher_subs, key=lambda sub: sub["lesson_id"]) return jsonify({"data": all_substitutions}) +@app.route("/api/date", methods=["GET"]) +def get_date(): + date = get_data.date() + return jsonify({"date": date}) @app.errorhandler(404) def not_found(error): From 929189c9e146cf60485859383ea9b3d78a986b2a Mon Sep 17 00:00:00 2001 From: Kacper Latuszewski Date: Tue, 18 Feb 2020 20:21:12 +0100 Subject: [PATCH 02/10] Fixes --- flask_app/get_data.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/flask_app/get_data.py b/flask_app/get_data.py index 16c6d199..e9bba910 100644 --- a/flask_app/get_data.py +++ b/flask_app/get_data.py @@ -32,13 +32,12 @@ def main(): def date(): with codecs.open( - "mocks/template.html", "r", "utf-8" + "Zastępstwa.html", "r", "utf-8" ) as f: # Zastępstwa.html in main folder soup = BeautifulSoup(f.read(), "html.parser") - h2 = soup.find_all("h2") - data = h2[0] + # it looks for

Okres: 26.11.2019 (wt.) - 26.11.2019 (wt.)

and takes date from it + data = soup.find("h2") date = str(data.text).split(' ')[1] - - return date - \ No newline at end of file + + return date \ No newline at end of file From dfb41fd40c4aefedd00b2c93e511eb09c61d4b09 Mon Sep 17 00:00:00 2001 From: Kacper Latuszewski Date: Tue, 18 Feb 2020 22:14:36 +0100 Subject: [PATCH 03/10] created constant file --- flask_app/get_data.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/flask_app/get_data.py b/flask_app/get_data.py index e9bba910..57e417da 100644 --- a/flask_app/get_data.py +++ b/flask_app/get_data.py @@ -4,10 +4,11 @@ import codecs from bs4 import BeautifulSoup +FILE = "Zastępstwa.html" def main(): with codecs.open( - "Zastępstwa.html", "r", "utf-8" + FILE, "r", "utf-8" ) as f: # Zastępstwa.html in main folder soup = BeautifulSoup(f.read(), "html.parser") @@ -32,7 +33,7 @@ def main(): def date(): with codecs.open( - "Zastępstwa.html", "r", "utf-8" + FILE, "r", "utf-8" ) as f: # Zastępstwa.html in main folder soup = BeautifulSoup(f.read(), "html.parser") From 3d3dbcd96729388a9fb3c6500c2c82a820d06535 Mon Sep 17 00:00:00 2001 From: Kacper Latuszewski Date: Wed, 19 Feb 2020 15:40:04 +0100 Subject: [PATCH 04/10] Linted and changed constant name --- flask_app/get_data.py | 20 +++++++++----------- flask_app/main.py | 2 ++ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/flask_app/get_data.py b/flask_app/get_data.py index 57e417da..4813af22 100644 --- a/flask_app/get_data.py +++ b/flask_app/get_data.py @@ -4,12 +4,11 @@ import codecs from bs4 import BeautifulSoup -FILE = "Zastępstwa.html" +FILENAME = "Zastępstwa.html" + def main(): - with codecs.open( - FILE, "r", "utf-8" - ) as f: # Zastępstwa.html in main folder + with codecs.open(FILENAME, "r", "utf-8") as f: # Zastępstwa.html in main folder soup = BeautifulSoup(f.read(), "html.parser") rows = soup.find_all("tr") @@ -31,14 +30,13 @@ def main(): replacements[teacher].append(lesson_info) return replacements + def date(): - with codecs.open( - FILE, "r", "utf-8" - ) as f: # Zastępstwa.html in main folder + with codecs.open(FILENAME, "r", "utf-8") as f: # Zastępstwa.html in main folder soup = BeautifulSoup(f.read(), "html.parser") # it looks for

Okres: 26.11.2019 (wt.) - 26.11.2019 (wt.)

and takes date from it - data = soup.find("h2") - date = str(data.text).split(' ')[1] - - return date \ No newline at end of file + data = soup.find("h2") + date = str(data.text).split(" ")[1] + + return date diff --git a/flask_app/main.py b/flask_app/main.py index 5638e235..a6eff14a 100644 --- a/flask_app/main.py +++ b/flask_app/main.py @@ -37,11 +37,13 @@ def get_all(): all_substitutions += sorted(teacher_subs, key=lambda sub: sub["lesson_id"]) return jsonify({"data": all_substitutions}) + @app.route("/api/date", methods=["GET"]) def get_date(): date = get_data.date() return jsonify({"date": date}) + @app.errorhandler(404) def not_found(error): return make_response(jsonify({"error": "Not found"}), 404) From 48034308849ff844a424c45fb5b32a77962402de Mon Sep 17 00:00:00 2001 From: Kacper Latuszewski Date: Wed, 19 Feb 2020 21:30:45 +0100 Subject: [PATCH 05/10] Showing date on fixed bottom, right corner --- frontend/src/components/SubstitutionDate.jsx | 27 ++++++++++++++++++++ frontend/src/view/AllSubstitutions.jsx | 3 +++ frontend/src/view/Home.jsx | 3 +++ frontend/src/view/Teacher.jsx | 3 +++ 4 files changed, 36 insertions(+) create mode 100644 frontend/src/components/SubstitutionDate.jsx diff --git a/frontend/src/components/SubstitutionDate.jsx b/frontend/src/components/SubstitutionDate.jsx new file mode 100644 index 00000000..f64922b2 --- /dev/null +++ b/frontend/src/components/SubstitutionDate.jsx @@ -0,0 +1,27 @@ +import React, { useState, useEffect } from 'react'; +import axios from 'axios'; +import styled from 'styled-components'; + +const SubstitutionDateWrapper = styled.div` + position: fixed; + bottom: 0; + right: 0; +`; + +const SubstitutionDate = () => { + const [date, setDate] = useState(""); + const [error, setError] = useState(null); + + useEffect(() => { + axios + .get(`/api/date`) + .then(({ data }) => setDate(data.date)) + .catch((err) => setError(String(err))); + }, []); + + return ( + Zastępstwa z dnia: {date} + ); +}; + +export default SubstitutionDate; diff --git a/frontend/src/view/AllSubstitutions.jsx b/frontend/src/view/AllSubstitutions.jsx index f3d7e179..8c8e6570 100644 --- a/frontend/src/view/AllSubstitutions.jsx +++ b/frontend/src/view/AllSubstitutions.jsx @@ -6,6 +6,8 @@ import TableSeparator from '../components/TableSeparator'; import TableTitle from '../components/TableTitle'; import ErrorMessage from '../components/ErrorMessage'; +import SubstitutionDate from '../components/SubstitutionDate' + const AllSubstitutions = () => { const [substitutions, setSubstitutions] = useState([]); const [error, setError] = useState(null); @@ -70,6 +72,7 @@ const AllSubstitutions = () => { {substitutions.map(generateLessonRow)} )} + ); }; diff --git a/frontend/src/view/Home.jsx b/frontend/src/view/Home.jsx index 92acbbeb..c1f5b624 100644 --- a/frontend/src/view/Home.jsx +++ b/frontend/src/view/Home.jsx @@ -4,6 +4,7 @@ import { Link } from 'react-router-dom'; import Button from '../components/Button'; import ErrorMessage from '../components/ErrorMessage'; +import SubstitutionDate from '../components/SubstitutionDate' const Home = () => { const [teachers, setTeachers] = useState([]); @@ -50,6 +51,8 @@ const Home = () => { > Wszystkie zastępstwa + + ); }; diff --git a/frontend/src/view/Teacher.jsx b/frontend/src/view/Teacher.jsx index e218e9a9..1e23ee4c 100644 --- a/frontend/src/view/Teacher.jsx +++ b/frontend/src/view/Teacher.jsx @@ -5,6 +5,7 @@ import { useParams } from 'react-router-dom'; import TeacherTable from '../components/TeacherTable'; import TableTitle from '../components/TableTitle'; import ErrorMessage from '../components/ErrorMessage'; +import SubstitutionDate from '../components/SubstitutionDate' const Teacher = () => { const { name } = useParams(); @@ -36,6 +37,8 @@ const Teacher = () => { ) : ( )} + + ); }; From 9cd2312b78135d28cd515ebd5d7028e33238fdc4 Mon Sep 17 00:00:00 2001 From: Kacper Latuszewski Date: Wed, 19 Feb 2020 21:34:59 +0100 Subject: [PATCH 06/10] Added error message and linted --- frontend/src/components/SubstitutionDate.jsx | 11 ++++++++++- frontend/src/view/AllSubstitutions.jsx | 2 +- frontend/src/view/Home.jsx | 2 +- frontend/src/view/Teacher.jsx | 2 +- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/frontend/src/components/SubstitutionDate.jsx b/frontend/src/components/SubstitutionDate.jsx index f64922b2..8592049c 100644 --- a/frontend/src/components/SubstitutionDate.jsx +++ b/frontend/src/components/SubstitutionDate.jsx @@ -2,6 +2,8 @@ import React, { useState, useEffect } from 'react'; import axios from 'axios'; import styled from 'styled-components'; +import ErrorMessage from "./ErrorMessage"; + const SubstitutionDateWrapper = styled.div` position: fixed; bottom: 0; @@ -20,7 +22,14 @@ const SubstitutionDate = () => { }, []); return ( - Zastępstwa z dnia: {date} + <> + + + Zastępstwa z dnia: + {' '} + {date} + + ); }; diff --git a/frontend/src/view/AllSubstitutions.jsx b/frontend/src/view/AllSubstitutions.jsx index 8c8e6570..7cf75fa4 100644 --- a/frontend/src/view/AllSubstitutions.jsx +++ b/frontend/src/view/AllSubstitutions.jsx @@ -72,7 +72,7 @@ const AllSubstitutions = () => { {substitutions.map(generateLessonRow)} )} - + ); }; diff --git a/frontend/src/view/Home.jsx b/frontend/src/view/Home.jsx index c1f5b624..c4459069 100644 --- a/frontend/src/view/Home.jsx +++ b/frontend/src/view/Home.jsx @@ -52,7 +52,7 @@ const Home = () => { Wszystkie zastępstwa - + ); }; diff --git a/frontend/src/view/Teacher.jsx b/frontend/src/view/Teacher.jsx index 1e23ee4c..755db9cc 100644 --- a/frontend/src/view/Teacher.jsx +++ b/frontend/src/view/Teacher.jsx @@ -38,7 +38,7 @@ const Teacher = () => { )} - + ); }; From 555b60de7687e696f86884bb99dffabad0687858 Mon Sep 17 00:00:00 2001 From: Kacper Latuszewski Date: Thu, 20 Feb 2020 10:29:05 +0100 Subject: [PATCH 07/10] Date position -> absolute, top, right corner --- frontend/src/App.jsx | 2 ++ frontend/src/components/SubstitutionDate.jsx | 14 +++++--------- frontend/src/view/AllSubstitutions.jsx | 3 --- frontend/src/view/Home.jsx | 3 --- frontend/src/view/Teacher.jsx | 3 --- 5 files changed, 7 insertions(+), 18 deletions(-) diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index f8c86df5..b6d44069 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -6,6 +6,7 @@ import Header from './components/Header'; import Teacher from './view/Teacher'; import Home from './view/Home'; import AllSubstitutions from './view/AllSubstitutions'; +import SubstitutionDate from './components/SubstitutionDate' const App = () => ( @@ -21,6 +22,7 @@ const App = () => ( + ); diff --git a/frontend/src/components/SubstitutionDate.jsx b/frontend/src/components/SubstitutionDate.jsx index 8592049c..754cbed6 100644 --- a/frontend/src/components/SubstitutionDate.jsx +++ b/frontend/src/components/SubstitutionDate.jsx @@ -2,31 +2,27 @@ import React, { useState, useEffect } from 'react'; import axios from 'axios'; import styled from 'styled-components'; -import ErrorMessage from "./ErrorMessage"; - const SubstitutionDateWrapper = styled.div` - position: fixed; - bottom: 0; + position: absolute; + top: 0; right: 0; + margin: 30px; + font-size: 30px; `; const SubstitutionDate = () => { const [date, setDate] = useState(""); - const [error, setError] = useState(null); useEffect(() => { axios .get(`/api/date`) .then(({ data }) => setDate(data.date)) - .catch((err) => setError(String(err))); + .catch((err) => err); }, []); return ( <> - - Zastępstwa z dnia: - {' '} {date} diff --git a/frontend/src/view/AllSubstitutions.jsx b/frontend/src/view/AllSubstitutions.jsx index 7cf75fa4..f3d7e179 100644 --- a/frontend/src/view/AllSubstitutions.jsx +++ b/frontend/src/view/AllSubstitutions.jsx @@ -6,8 +6,6 @@ import TableSeparator from '../components/TableSeparator'; import TableTitle from '../components/TableTitle'; import ErrorMessage from '../components/ErrorMessage'; -import SubstitutionDate from '../components/SubstitutionDate' - const AllSubstitutions = () => { const [substitutions, setSubstitutions] = useState([]); const [error, setError] = useState(null); @@ -72,7 +70,6 @@ const AllSubstitutions = () => { {substitutions.map(generateLessonRow)} )} - ); }; diff --git a/frontend/src/view/Home.jsx b/frontend/src/view/Home.jsx index c4459069..92acbbeb 100644 --- a/frontend/src/view/Home.jsx +++ b/frontend/src/view/Home.jsx @@ -4,7 +4,6 @@ import { Link } from 'react-router-dom'; import Button from '../components/Button'; import ErrorMessage from '../components/ErrorMessage'; -import SubstitutionDate from '../components/SubstitutionDate' const Home = () => { const [teachers, setTeachers] = useState([]); @@ -51,8 +50,6 @@ const Home = () => { > Wszystkie zastępstwa - - ); }; diff --git a/frontend/src/view/Teacher.jsx b/frontend/src/view/Teacher.jsx index 755db9cc..e218e9a9 100644 --- a/frontend/src/view/Teacher.jsx +++ b/frontend/src/view/Teacher.jsx @@ -5,7 +5,6 @@ import { useParams } from 'react-router-dom'; import TeacherTable from '../components/TeacherTable'; import TableTitle from '../components/TableTitle'; import ErrorMessage from '../components/ErrorMessage'; -import SubstitutionDate from '../components/SubstitutionDate' const Teacher = () => { const { name } = useParams(); @@ -37,8 +36,6 @@ const Teacher = () => { ) : ( )} - - ); }; From 3dca314f07cc5b24c957098eed8382d299adc65f Mon Sep 17 00:00:00 2001 From: Kacper Latuszewski Date: Thu, 20 Feb 2020 21:13:36 +0100 Subject: [PATCH 08/10] date to header, error --- frontend/src/App.jsx | 2 -- frontend/src/components/Header.jsx | 2 ++ frontend/src/components/SubstitutionDate.jsx | 8 ++++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index b6d44069..f8c86df5 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -6,7 +6,6 @@ import Header from './components/Header'; import Teacher from './view/Teacher'; import Home from './view/Home'; import AllSubstitutions from './view/AllSubstitutions'; -import SubstitutionDate from './components/SubstitutionDate' const App = () => ( @@ -22,7 +21,6 @@ const App = () => ( - ); diff --git a/frontend/src/components/Header.jsx b/frontend/src/components/Header.jsx index a8476737..51c066db 100644 --- a/frontend/src/components/Header.jsx +++ b/frontend/src/components/Header.jsx @@ -3,6 +3,7 @@ import { Link } from 'react-router-dom'; import styled from 'styled-components'; import logo from '../assets/logo-zsk.svg'; +import SubstitutionDate from "./SubstitutionDate" const HeaderLink = styled(Link)` display: flex; @@ -27,6 +28,7 @@ const Header = () => (

Zastępstwa

+ ); diff --git a/frontend/src/components/SubstitutionDate.jsx b/frontend/src/components/SubstitutionDate.jsx index 754cbed6..c7c383ba 100644 --- a/frontend/src/components/SubstitutionDate.jsx +++ b/frontend/src/components/SubstitutionDate.jsx @@ -12,21 +12,25 @@ const SubstitutionDateWrapper = styled.div` const SubstitutionDate = () => { const [date, setDate] = useState(""); + const [error, setError] = useState(""); useEffect(() => { axios .get(`/api/date`) .then(({ data }) => setDate(data.date)) - .catch((err) => err); + .catch((err) => setError(err)); }, []); return ( <> - {date} + {error || ( + date + )} ); + }; export default SubstitutionDate; From 6b3ee0692559a3e1c1867ce9c3a55f57cde5982a Mon Sep 17 00:00:00 2001 From: Kacper Latuszewski Date: Fri, 21 Feb 2020 13:25:43 +0100 Subject: [PATCH 09/10] Error style --- frontend/src/components/SubstitutionDate.jsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/frontend/src/components/SubstitutionDate.jsx b/frontend/src/components/SubstitutionDate.jsx index c7c383ba..e2fd0539 100644 --- a/frontend/src/components/SubstitutionDate.jsx +++ b/frontend/src/components/SubstitutionDate.jsx @@ -24,9 +24,11 @@ const SubstitutionDate = () => { return ( <> - {error || ( - date - )} + {error ? ( +

Nie udało się pobrać daty

+ ) : ( + date + )}
); From 4845bf44cf282f494de2e7c09abdbf11ab4be48e Mon Sep 17 00:00:00 2001 From: Kacper Latuszewski Date: Sun, 23 Feb 2020 20:44:39 +0100 Subject: [PATCH 10/10] Refresh date every 1 minute --- frontend/src/components/SubstitutionDate.jsx | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/frontend/src/components/SubstitutionDate.jsx b/frontend/src/components/SubstitutionDate.jsx index e2fd0539..e5f787cb 100644 --- a/frontend/src/components/SubstitutionDate.jsx +++ b/frontend/src/components/SubstitutionDate.jsx @@ -12,13 +12,18 @@ const SubstitutionDateWrapper = styled.div` const SubstitutionDate = () => { const [date, setDate] = useState(""); - const [error, setError] = useState(""); + const [error, setError] = useState(""); + + const getData = () => + axios + .get(`/api/date`) + .then(({ data }) => setDate(data.date)) + .catch((err) => setError(String(err))); useEffect(() => { - axios - .get(`/api/date`) - .then(({ data }) => setDate(data.date)) - .catch((err) => setError(err)); + getData(); + const refreshId = setInterval(getData, 60000); + return () => clearInterval(refreshId); }, []); return (