This repository has been archived on 2019-10-13. You can view files and clone it, but cannot push or open issues or pull requests.
basta-server/ofu-food/fekide-happyhour-page-parser.py
2017-09-24 02:00:33 +02:00

54 lines
1.4 KiB
Python

import requests
from bs4 import BeautifulSoup
import datetime
import json
SPEISEPLAN_NAME_SELECTOR = '.csc-default .csc-header .csc-firstHeader'
def loadPage(url: str):
return requests.get(url).content
def getDay():
return datetime.datetime.today().strftime("%A, %d.%m.%Y")
def getHappyHours(soup):
happyhours = []
happyhourstable = soup.select('#food .table tr')
for tableline in happyhourstable:
happyhour = {}
linesoup = BeautifulSoup(str(tableline), "lxml")
location = linesoup.find("td", {"class": "location"}).getText()
time = linesoup.find("td", {"class": "time"}).getText()
description = linesoup.find("td", {"class": "description"}).getText()
description = str(description).strip()
happyhour['location'] = location
happyhour['time'] = time
happyhour['description'] = description
happyhours.append(happyhour)
return happyhours
def parsePage(url: str):
pagecontent = {}
# {
# happyhours:[{happyhour:{location: "",time: "",description: ""},,,,]
# }
happyhours = []
page = loadPage(url)
soup = BeautifulSoup(page, "lxml")
happyhours = getHappyHours(soup)
pagecontent['happyhours'] = happyhours
pagecontent['day'] = getDay()
jsondata = json.dumps(pagecontent)
return jsondata
# LINK_FEKIDE_GUIDE = "https://www.feki.de/happyhour/wochenuebersicht"
# parsePage(LINK_FEKIDE_GUIDE)