From 47992860d1236f78d007ae7c6a1b1beed92814dc Mon Sep 17 00:00:00 2001
From: Lukas Winkler
Date: Sun, 11 Jun 2017 21:10:12 +0200
Subject: [PATCH] add aai
---
main.py | 2 +-
parser/__init__.py | 3 +-
parser/aai.py | 50 ++++++++
website.py | 304 +++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 357 insertions(+), 2 deletions(-)
create mode 100644 parser/aai.py
diff --git a/main.py b/main.py
index d41ca9e..25db08c 100644
--- a/main.py
+++ b/main.py
@@ -18,7 +18,7 @@ try:
check_meal_sql = "SELECT id FROM meals WHERE name=%s"
insert_meal_sql = "INSERT INTO meals (name) VALUE (%s)"
insert_sql = 'REPLACE INTO menus (venue, date, meal) VALUES (%s, %s, %s)'
- for p in [parser.fladerei, parser.zuppa]:
+ for p in [parser.fladerei, parser.zuppa, parser.aai]:
cursor.execute(venue_sql, p.name)
venue_id = cursor.fetchone()["id"]
for i in p.get_menus():
diff --git a/parser/__init__.py b/parser/__init__.py
index 68b4734..99a8723 100644
--- a/parser/__init__.py
+++ b/parser/__init__.py
@@ -1,2 +1,3 @@
from . import fladerei
-from . import zuppa
\ No newline at end of file
+from . import zuppa
+from . import aai
\ No newline at end of file
diff --git a/parser/aai.py b/parser/aai.py
new file mode 100644
index 0000000..7bd1287
--- /dev/null
+++ b/parser/aai.py
@@ -0,0 +1,50 @@
+import re
+from datetime import datetime, timedelta
+
+import requests
+from bs4 import BeautifulSoup
+
+import config
+
+name = "aai"
+
+fetch_url = "http://www.aai-wien.at/aai-mensa"
+
+dateregex = re.compile("plan (\d{2}\.\d{2}\.)")
+
+
+def fetch_recourse():
+ if config.DEBUG:
+ from website import aai_html as html
+ else:
+ r = requests.get(fetch_url)
+ html = r.text
+ return html
+
+
+def get_menus():
+ tagesmenus = []
+ html = fetch_recourse()
+ startdatestring = dateregex.search(html).groups()[0]
+ startdate = datetime.strptime(startdatestring, "%d.%m.").replace(year=datetime.today().year)
+ print(startdate)
+ soup = BeautifulSoup(html, 'html.parser')
+ table = soup.find("table", {"class": "mitrand", "border": "1", "align": "center"})
+ i = 0
+ for tr in table.tbody.findAll("tr"):
+ menutype = tr.td.text.strip()
+ if not menutype:
+ continue
+ for td in tr.findAll("td")[1:]:
+ tagesmenu = {
+ "type": menutype,
+ "name": td.text.split("(")[0].strip(),
+ "date": startdate + timedelta(days=i)
+ }
+ tagesmenus.append(tagesmenu)
+ i += 1
+ return tagesmenus
+
+
+if __name__ == '__main__':
+ print(get_menus())
diff --git a/website.py b/website.py
index a3fdd91..dc44a1a 100644
--- a/website.py
+++ b/website.py
@@ -504,6 +504,310 @@ gerne auf vorbestellung 4,50
+