„chemnitz.kitchen_scaper.py“ ändern

zeigt nun den das bestellte menü heute / morgen an
main
maik 3 years ago
parent 71ea5e2d77
commit 9c628763ae
  1. 53
      chemnitz.kitchen_scaper.py

@ -1,20 +1,24 @@
import requests
import json
import datetime
from bs4 import BeautifulSoup
from datetime import date
# Variablen
errorMsg = ('HEUTE KEIN ESSEN')
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:')
today = date.today()
today_url = today.strftime("%d.%m.%Y")
#today_url = ('05.12.22')
# Login URL
loginurl = ('https://chemnitz.kitchen/login/')
# Bestellübersicht
menu_url = f'https://chemnitz.kitchen/kunden/bestelluebersicht/?date_from={today_url}&date_to={today_url}'
menu_url = f'https://chemnitz.kitchen/kunden/bestelluebersicht/?date_from={convert_today}&date_to={convert_tomorrow}'
#Logindaten
login = {
@ -29,26 +33,39 @@ with requests.session() as s:
soup = BeautifulSoup(p.content, 'html.parser')
table = soup.find('table' ,attrs={'class':'food-order'})
rows = table.find_all('td')
description = rows[2].get_text()
menu = rows[1].get_text()
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 = {
f'date': today_url,
f'menu': menu,
f'description': description }
dictionary_string = json.dumps(JsonDictionary, ensure_ascii=False,)
dataString = dictionary_string
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}'
textout = f' {menuMsg} {description_today}'
datei = open("ck.json", "w", encoding="utf-8")
datei.writelines(dictionary_string)
datei.close()
print(textout)
print(dictionary_string)
print('Heute:', menu_today, description_today )
print('Morgen:', menu_tomorrow, description_tomorrow)
print(JsonDictionary)

Loading…
Cancel
Save