diff --git a/lib/modules/fetchMenu.dart b/lib/modules/fetchMenu.dart index 65f0800..bfe6b0c 100644 --- a/lib/modules/fetchMenu.dart +++ b/lib/modules/fetchMenu.dart @@ -1,5 +1,8 @@ import 'dart:convert'; import 'dart:io'; +import 'package:xml/xml.dart'; + + import 'package:http/http.dart' as http; import 'package:shared_preferences/shared_preferences.dart'; @@ -25,18 +28,23 @@ class FetchMenu { return await loadCache(); } - static Future> fromRequest() async { - List menus = []; - http.Response resp = await http.get(Uri.parse( - "https://www.swfr.de/essen/mensen-cafes-speiseplaene/mensa-loerrach")); - var content = resp.body.split("

"); - var innerContent = content[1].split("\n"); - for (var s in innerContent) { - if (s.contains("extra-text mb-15px")) { - var name = (s.split("\">")[1].split("", " "); - menus.add(name); + static Future> fromRequest() async { + List menus = []; + var now = DateTime.now(); + var today = "${now.day.toString().padLeft(2, '0')}.${now.month.toString().padLeft(2, '0')}.${now.year}"; + + http.Response resp = await http.get(Uri.parse( + "https://www.swfr.de/apispeiseplan?&type=98&tx_speiseplan_pi1[apiKey]=c3841e89a2c8c301b890723ecdb786ad&tx_speiseplan_pi1[ort]=677")); //Api Key lays here, modify this shit when you have time + var xmlContent = XmlDocument.parse(utf8.decode(resp.bodyBytes)); + for (var tagesplan in xmlContent.findAllElements("tagesplan")){ + var datum = tagesplan.getAttribute('datum')?.trim(); + if (datum == today){ + for (var menu in tagesplan.findElements('menue')){ + var name = menu.findElements('name').map((e) => e.text).join(", "); + menus.add(name); + } + } } - } await storeCache(menus); diff --git a/pubspec.lock b/pubspec.lock index d827ff6..879bb3e 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -224,6 +224,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.3.0" + petitparser: + dependency: transitive + description: + name: petitparser + sha256: c15605cd28af66339f8eb6fbe0e541bfe2d1b72d5825efc6598f3e0a31b9ad27 + url: "https://pub.dev" + source: hosted + version: "6.0.2" platform: dependency: transitive description: @@ -397,6 +405,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.1.0" + xml: + dependency: "direct main" + description: + name: xml + sha256: b015a8ad1c488f66851d762d3090a21c600e479dc75e68328c52774040cf9226 + url: "https://pub.dev" + source: hosted + version: "6.5.0" sdks: dart: ">=3.5.2 <4.0.0" flutter: ">=3.24.0" diff --git a/pubspec.yaml b/pubspec.yaml index 8366f4d..21f495c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -35,6 +35,7 @@ dependencies: flutter_rating_bar: ^4.0.1 http: ^1.2.2 shared_preferences: ^2.3.3 + xml: ^6.5.0 # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons.