Kleiner Script der schaut was es heute zu Essen gibt (work in prozess)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
chemnitz-kitchen-scraper/chemnitz.kitchen_scaper.py

71 lines
1.7 KiB

import requests
import json
import datetime
from bs4 import BeautifulSoup
# Variablen
today = datetime.date.today()
tomorrow = today + datetime.timedelta(days = 1)
convert_today = today.strftime("%d.%m.%Y")
convert_tomorrow = tomorrow.strftime("%d.%m.%Y")
menuMsg = ('Du hast bei Chemnitz.Kitchen bestellt! Heute gibt es:')
# Login URL
loginurl = ('https://chemnitz.kitchen/login/')
# Bestellübersicht
menu_url = f'https://chemnitz.kitchen/kunden/bestelluebersicht/?date_from={convert_today}&date_to={convert_tomorrow}'
#Logindaten
login = {
'username': 'email',
'password': 'password'
}
# Einloggen und auf Bestellübersicht springen
with requests.session() as s:
s.post(loginurl, data=login)
p = s.get(menu_url)
soup = BeautifulSoup(p.content, 'html.parser')
table = soup.find('table' ,attrs={'class':'food-order'})
rows = table.find_all('td')
description_today = rows[2].get_text()
menu_today = rows[1].get_text()
description_tomorrow = rows[8].get_text()
menu_tomorrow = rows[7].get_text()
#JSON
JsonDictionary = {
"Daten": [
{
f'today': 'HEUTE',
f'menu': menu_today,
f'description': description_today },
{
f'tomorrow': 'MORGEN',
f'menu': menu_tomorrow,
f'description': description_tomorrow }
]
}
dictionary_string = json.dumps(JsonDictionary, ensure_ascii=False,)
dataString = dictionary_string
textout = f' {menuMsg} {description_today}'
datei = open("ck.json", "w", encoding="utf-8")
datei.writelines(dictionary_string)
datei.close()
print('Heute:', menu_today, description_today )
print('Morgen:', menu_tomorrow, description_tomorrow)
print(JsonDictionary)