-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
executable file
·45 lines (32 loc) · 1.1 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/python3
from bs4 import BeautifulSoup
import urllib.request
from flask import Flask, Response
import json
def get_menu():
with urllib.request.urlopen("http://www.zs23.wroclaw.pl/internat/jadlospis.php") as url:
html_doc = url.read()
soup = BeautifulSoup(html_doc, 'html.parser')
ignore = True
menu = []
for tr in soup.table.find_all("tr"):
if tr.get_text().strip() in ["Poniedziałek", "Wtorek", "Środa", "Czwartek", "Piątek"]:
ignore = False
continue
if ignore or tr.get_text().strip() == "":
continue
day = []
for bobiad in tr.find_all("td", class_="bobiad"):
if bobiad.get_text().strip() != '':
day.append(bobiad.get_text().strip())
menu.append(day)
return menu
app = Flask(__name__)
@app.route("/")
def root():
return Response("Stolowka 23 menu API. Try /menu\n", mimetype="text/plain")
@app.route("/menu")
def menu():
return Response(json.dumps(get_menu()), mimetype='application/json; charset=utf-8')
if __name__ == '__main__':
app.run('0.0.0.0')