From 9c628763ae5aab34519941fbf395cb331d3c229e Mon Sep 17 00:00:00 2001 From: maik Date: Tue, 6 Dec 2022 19:24:25 +0000 Subject: [PATCH] =?UTF-8?q?=E2=80=9Echemnitz.kitchen=5Fscaper.py=E2=80=9C?= =?UTF-8?q?=20=C3=A4ndern?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit zeigt nun den das bestellte menü heute / morgen an --- chemnitz.kitchen_scaper.py | 53 +++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/chemnitz.kitchen_scaper.py b/chemnitz.kitchen_scaper.py index 16436ac..32f90ea 100644 --- a/chemnitz.kitchen_scaper.py +++ b/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)