Skip to content

Commit

Permalink
Merge pull request #63 from zsk-poznan/develop
Browse files Browse the repository at this point in the history
v0.4
  • Loading branch information
pniedzwiedzinski authored Feb 25, 2020
2 parents a51e2d5 + 7b5fcec commit a289e89
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 3 deletions.
17 changes: 14 additions & 3 deletions backend/get_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import codecs
from bs4 import BeautifulSoup

FILENAME = "Zastępstwa.html"


def main():
with codecs.open(
"Zastępstwa.html", "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")
Expand All @@ -29,3 +29,14 @@ def main():
else:
replacements[teacher].append(lesson_info)
return replacements


def date():
with codecs.open(FILENAME, "r", "utf-8") as f: # Zastępstwa.html in main folder
soup = BeautifulSoup(f.read(), "html.parser")

# it looks for <h2>Okres: 26.11.2019 (wt.) - 26.11.2019 (wt.)</h2> and takes date from it
data = soup.find("h2")
date = str(data.text).split(" ")[1]

return date
6 changes: 6 additions & 0 deletions backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ def get_all():
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)
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/components/Header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,6 +28,7 @@ const Header = () => (
<ImageWrapper src={logo} alt="ZSK" />
<h1>Zastępstwa</h1>
</HeaderLink>
<SubstitutionDate />
</header>
);

Expand Down
43 changes: 43 additions & 0 deletions frontend/src/components/SubstitutionDate.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import React, { useState, useEffect } from 'react';
import axios from 'axios';
import styled from 'styled-components';

const SubstitutionDateWrapper = styled.div`
position: absolute;
top: 0;
right: 0;
margin: 30px;
font-size: 30px;
`;

const SubstitutionDate = () => {
const [date, setDate] = useState("");
const [error, setError] = useState("");

const getData = () =>
axios
.get(`/api/date`)
.then(({ data }) => setDate(data.date))
.catch((err) => setError(String(err)));

useEffect(() => {
getData();
const refreshId = setInterval(getData, 60000);
return () => clearInterval(refreshId);
}, []);

return (
<>
<SubstitutionDateWrapper>
{error ? (
<p style={{color: 'red', fontSize: '16px'}}>Nie udało się pobrać daty</p>
) : (
date
)}
</SubstitutionDateWrapper>
</>
);

};

export default SubstitutionDate;

0 comments on commit a289e89

Please sign in to comment.