Puuush
HTML Parsing -> changed to XML Parsing over API
This commit is contained in:
@@ -1,5 +1,8 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
import 'package:xml/xml.dart';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
@@ -27,16 +30,21 @@ class FetchMenu {
|
|||||||
|
|
||||||
static Future<List<String>> fromRequest() async {
|
static Future<List<String>> fromRequest() async {
|
||||||
List<String> menus = [];
|
List<String> 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(
|
http.Response resp = await http.get(Uri.parse(
|
||||||
"https://www.swfr.de/essen/mensen-cafes-speiseplaene/mensa-loerrach"));
|
"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 content = resp.body.split("<h3>");
|
var xmlContent = XmlDocument.parse(utf8.decode(resp.bodyBytes));
|
||||||
var innerContent = content[1].split("\n");
|
for (var tagesplan in xmlContent.findAllElements("tagesplan")){
|
||||||
for (var s in innerContent) {
|
var datum = tagesplan.getAttribute('datum')?.trim();
|
||||||
if (s.contains("extra-text mb-15px")) {
|
if (datum == today){
|
||||||
var name = (s.split("\">")[1].split("</")[0]).replaceAll("<br>", " ");
|
for (var menu in tagesplan.findElements('menue')){
|
||||||
|
var name = menu.findElements('name').map((e) => e.text).join(", ");
|
||||||
menus.add(name);
|
menus.add(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
await storeCache(menus);
|
await storeCache(menus);
|
||||||
|
|
||||||
|
|||||||
@@ -224,6 +224,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.3.0"
|
version: "2.3.0"
|
||||||
|
petitparser:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: petitparser
|
||||||
|
sha256: c15605cd28af66339f8eb6fbe0e541bfe2d1b72d5825efc6598f3e0a31b9ad27
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "6.0.2"
|
||||||
platform:
|
platform:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@@ -397,6 +405,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.1.0"
|
version: "1.1.0"
|
||||||
|
xml:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: xml
|
||||||
|
sha256: b015a8ad1c488f66851d762d3090a21c600e479dc75e68328c52774040cf9226
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "6.5.0"
|
||||||
sdks:
|
sdks:
|
||||||
dart: ">=3.5.2 <4.0.0"
|
dart: ">=3.5.2 <4.0.0"
|
||||||
flutter: ">=3.24.0"
|
flutter: ">=3.24.0"
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ dependencies:
|
|||||||
flutter_rating_bar: ^4.0.1
|
flutter_rating_bar: ^4.0.1
|
||||||
http: ^1.2.2
|
http: ^1.2.2
|
||||||
shared_preferences: ^2.3.3
|
shared_preferences: ^2.3.3
|
||||||
|
xml: ^6.5.0
|
||||||
|
|
||||||
# The following adds the Cupertino Icons font to your application.
|
# The following adds the Cupertino Icons font to your application.
|
||||||
# Use with the CupertinoIcons class for iOS style icons.
|
# Use with the CupertinoIcons class for iOS style icons.
|
||||||
|
|||||||
Reference in New Issue
Block a user