Puuush
HTML Parsing -> changed to XML Parsing over API
This commit is contained in:
+19
-11
@@ -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<List<String>> fromRequest() async {
|
||||
List<String> menus = [];
|
||||
http.Response resp = await http.get(Uri.parse(
|
||||
"https://www.swfr.de/essen/mensen-cafes-speiseplaene/mensa-loerrach"));
|
||||
var content = resp.body.split("<h3>");
|
||||
var innerContent = content[1].split("\n");
|
||||
for (var s in innerContent) {
|
||||
if (s.contains("extra-text mb-15px")) {
|
||||
var name = (s.split("\">")[1].split("</")[0]).replaceAll("<br>", " ");
|
||||
menus.add(name);
|
||||
static Future<List<String>> fromRequest() async {
|
||||
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(
|
||||
"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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user