import requests
from bs4 import BeautifulSoup
import urllib
import datetime
from shutil import copyfile
OUTPUTFILE = "../ofu-food.html"
# OUTPUTFILE = "/media/data_1/www/html/ofu-food.html"
CSSFILE_SRC = "../bootstrap-4.0.0-beta-dist/css/bootstrap.css"
CSSFILE = "bootstrap.css"
LINK_FEKI_MENSA = "https://www.studentenwerk-wuerzburg.de/bamberg/essen-trinken/speiseplaene.html?tx_thmensamenu_pi2%5Bmensen%5D=3&tx_thmensamenu_pi2%5Baction%5D=show&tx_thmensamenu_pi2%5Bcontroller%5D=Speiseplan&cHash=c3fe5ebb35e5fba3794f01878e798b7c"
LINK_AUSTR_MENSA = "https://www.studentenwerk-wuerzburg.de/bamberg/essen-trinken/speiseplaene.html?tx_thmensamenu_pi2%5Bmensen%5D=2&tx_thmensamenu_pi2%5Baction%5D=show&tx_thmensamenu_pi2%5Bcontroller%5D=Speiseplan&cHash=511e047953ee1370c3b82c11a04624bb"
LINK_ERBA_CAFETE = "https://www.studentenwerk-wuerzburg.de/bamberg/essen-trinken/sonderspeiseplaene/cafeteria-erba-insel.html"
LINK_MARKUS_CAFETE = "https://www.studentenwerk-wuerzburg.de/bamberg/essen-trinken/sonderspeiseplaene/cafeteria-markusplatz.html"
LINK_FEKIDE_GUIDE = "https://www.feki.de/happyhour"
def getHtmlHeader():
head = '
'
head += ' '
head += ' '
head += ' '
head += ' '
head += 'Essen an der OFU '
head += ''
return head
def getExecuteTime():
return "Last execute: " + datetime.datetime.today().strftime("%d.%m.%Y") + "
"
def getFoodHtml(erbaHtml, markusHtml, austrHtml, fekiHtml, happyHourHtml):
html = ''
html += ''
html += getHtmlHeader()
html += ''
html += getExecuteTime()
html += ''
html += str(erbaHtml)
html += str(markusHtml)
html += str(austrHtml)
html += str(fekiHtml)
html += str(happyHourHtml)
html += '
'
html += ''
html += ''
return html
def getFoodDiv(html, divClass):
soup = BeautifulSoup(html, "lxml")
return soup.find("div", {"class": divClass})
def getHappyHourGuideFood(html):
soup = BeautifulSoup(html, "lxml")
return soup.find("div", {"id": "food"})
def getWebPages():
erbaCafete = requests.get(LINK_ERBA_CAFETE).content
markusCafete = requests.get(LINK_MARKUS_CAFETE).content
austrMensa = requests.get(LINK_AUSTR_MENSA).content
fekiMensa = requests.get(LINK_FEKI_MENSA).content
happyHourGuide = requests.get(LINK_FEKIDE_GUIDE).content
return (erbaCafete, markusCafete, austrMensa, fekiMensa, happyHourGuide)
def getSpecificParts():
erbaCafete, markusCafete, austrMensa, fekiMensa, happyHourGuide = getWebPages()
erbaCafeteFood = getFoodDiv(erbaCafete, "csc-default")
markusCafeteFood = getFoodDiv(markusCafete, "csc-default")
austrMensaFood = getFoodDiv(austrMensa, "day")
fekiMensaFood = getFoodDiv(fekiMensa, "day")
happyHourGuideFood = getHappyHourGuideFood(happyHourGuide)
return (erbaCafeteFood, markusCafeteFood, austrMensaFood, fekiMensaFood, happyHourGuideFood)
def writeHtml(html):
with open(OUTPUTFILE, "w") as file:
file.write(html)
def stripCafeteFood(html):
soup = BeautifulSoup(str(html), "lxml")
food = soup.find_all("p", {"class": "bodytext"})
return food[(food.__len__() - 2)]
def htmlErbaCafete(food):
html = 'Cafeteria Erba-Insel '
html += str(food)
return html
def htmlMarkusCafete(food):
html = 'Cafeteria Markusplatz '
html += str(food)
return html
def htmlHappyHour(food):
html = 'Feki.de Happy Hour Guide '
html += str(food)
return html
def getFoodMensa(austrMensaFood, title):
html = ''
html += '
' + title + ' '
soup = BeautifulSoup(str(austrMensaFood), "lxml")
foodDay = soup.find("div", {"class": "day"}).h5
html += str(foodDay)
foods = soup.find_all("article", {"class": "menu"})
for food in foods:
soupSingleFood = BeautifulSoup(str(food), "lxml")
singleFood = soupSingleFood.find("div", {"class": "title"})
alergenLink = soupSingleFood.find("div", {"class": "additnr"}).a
html += str(singleFood)
html += str(alergenLink)
html += ''
return html
def main():
(erbaCafeteFood, markusCafeteFood, austrMensaFood, fekiMensaFood, happyHourGuideFood) = getSpecificParts()
erbaCafeteFood = stripCafeteFood(erbaCafeteFood)
erbaCafeteFood = htmlErbaCafete(erbaCafeteFood)
markusCafeteFood = stripCafeteFood(markusCafeteFood)
markusCafeteFood = htmlMarkusCafete(markusCafeteFood)
happyHourGuideFood = htmlHappyHour(happyHourGuideFood)
austrMensaFood = getFoodMensa(austrMensaFood, "Mensa Austraße")
fekiMensaFood = getFoodMensa(fekiMensaFood, "Feki Mensa")
html = getFoodHtml(erbaCafeteFood, markusCafeteFood, austrMensaFood, fekiMensaFood, happyHourGuideFood)
writeHtml(html)
main()
copyfile(CSSFILE_SRC, CSSFILE)