Return CURRENT event if asked for montagsküche
This commit is contained in:
parent
4718cc8d7e
commit
1901d76e4d
36
app.py
36
app.py
@ -5,6 +5,7 @@ import os
|
|||||||
from flask import Flask,redirect
|
from flask import Flask,redirect
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
import requests
|
import requests
|
||||||
|
from datetime import date
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
@ -50,7 +51,7 @@ def modultafeln(course=""):
|
|||||||
"wi": "Wirtschaftsinformatik/Bachelor/2015/",
|
"wi": "Wirtschaftsinformatik/Bachelor/2015/",
|
||||||
"wiw": "Wirtschaftsingenieurwesen/Bachelor/2015/?vertiefung=MB"
|
"wiw": "Wirtschaftsingenieurwesen/Bachelor/2015/?vertiefung=MB"
|
||||||
}
|
}
|
||||||
|
|
||||||
return redirect("https://www.tu-ilmenau.de/modultafeln/" + courseToPath.get(course, ""), code=302)
|
return redirect("https://www.tu-ilmenau.de/modultafeln/" + courseToPath.get(course, ""), code=302)
|
||||||
|
|
||||||
@app.route('/mail/')
|
@app.route('/mail/')
|
||||||
@ -113,15 +114,40 @@ def bi_club():
|
|||||||
# Montagsküche
|
# Montagsküche
|
||||||
@app.route('/montag/')
|
@app.route('/montag/')
|
||||||
def montagskueche():
|
def montagskueche():
|
||||||
|
# Get the startpage of bi club
|
||||||
try:
|
try:
|
||||||
posts = requests.get("https://www.bi-club.de/tags/montagskueche")
|
current_event = requests.get("https://www.bi-club.de/")
|
||||||
soup = BeautifulSoup(posts.text, 'html.parser')
|
current_soup = BeautifulSoup(current_event.text, 'html.parser')
|
||||||
link = soup.find(id='main').article.header.h2.a.get('href')
|
# Get an array of all events
|
||||||
return redirect("https://www.bi-club.de" + link, code=302)
|
events = current_soup.find(id='main').div.div.div.div.div.div.div.div.find_all('div', recursive=False)
|
||||||
except:
|
except:
|
||||||
return redirect("https://www.bi-club.de/tags/montagskueche", code=302)
|
return redirect("https://www.bi-club.de/tags/montagskueche", code=302)
|
||||||
|
|
||||||
|
# Pseudo event
|
||||||
|
next_montagskueche = date.max
|
||||||
|
next_montagskueche_url = ""
|
||||||
|
|
||||||
|
for event in events:
|
||||||
|
# Get interesting information
|
||||||
|
content = event.div.div.div.div.find_all('div', recursive=False)[1]
|
||||||
|
# Get title
|
||||||
|
title = content.h2.a.text
|
||||||
|
# Get date
|
||||||
|
date_string = content.div.div.span.text.split(' - ')[1].split('.')
|
||||||
|
date_object = date(int(date_string[2]), int(date_string[1]), int(date_string[0]))
|
||||||
|
# Get url
|
||||||
|
url = content.h2.a.get('href')
|
||||||
|
|
||||||
|
# Select the event
|
||||||
|
if "Montagsküche" in title and date_object >= date.today() and date_object < next_montagskueche:
|
||||||
|
next_montagskueche = date_object
|
||||||
|
next_montagskueche_url = url
|
||||||
|
|
||||||
|
# Answer
|
||||||
|
if next_montagskueche_url != "":
|
||||||
|
return redirect(next_montagskueche_url, code=302)
|
||||||
|
else:
|
||||||
|
return redirect("https://www.bi-club.de/tags/montagskueche", code=302)
|
||||||
|
|
||||||
########################################################################################################################
|
########################################################################################################################
|
||||||
# Stura
|
# Stura
|
||||||
|
Loading…
Reference in New Issue
Block a user