implemented importer für Bandhaus Leipzug
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
/* © SRSoftware 2024 */
|
||||
package de.srsoftware.cal;
|
||||
|
||||
import static de.srsoftware.cal.Util.combine;
|
||||
import static de.srsoftware.cal.Util.url;
|
||||
import static de.srsoftware.cal.Util.*;
|
||||
import static de.srsoftware.tools.Error.error;
|
||||
import static de.srsoftware.tools.Optionals.nullIfEmpty;
|
||||
import static de.srsoftware.tools.Result.transform;
|
||||
import static de.srsoftware.tools.Tag.HREF;
|
||||
import static de.srsoftware.tools.TagFilter.*;
|
||||
@@ -13,6 +13,8 @@ import de.srsoftware.tools.*;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.*;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.time.LocalDate;
|
||||
@@ -40,18 +42,18 @@ public abstract class BaseImporter implements Importer {
|
||||
|
||||
protected List<Attachment> extractAttachments(Tag eventTag) {
|
||||
return extractAttachmentsTag(eventTag) //
|
||||
.optional()
|
||||
.stream()
|
||||
.flatMap(tag -> tag.find(IS_IMAGE).stream())
|
||||
.map(tag -> tag.get("src"))
|
||||
.filter(Objects::nonNull)
|
||||
.map(url -> url.contains("://") ? url : baseUrl()+url)
|
||||
.map(Payload::of)
|
||||
.map(Util::url)
|
||||
.map(Util::toAttachment)
|
||||
.map(Result::optional)
|
||||
.flatMap(Optional::stream)
|
||||
.toList();
|
||||
.optional()
|
||||
.stream()
|
||||
.flatMap(tag -> tag.find(IS_IMAGE).stream())
|
||||
.map(tag -> tag.get("src"))
|
||||
.filter(Objects::nonNull)
|
||||
.map(url -> url.contains("://") ? url : baseUrl()+url)
|
||||
.map(Payload::of)
|
||||
.map(Util::url)
|
||||
.map(Util::toAttachment)
|
||||
.map(Result::optional)
|
||||
.flatMap(Optional::stream)
|
||||
.toList();
|
||||
}
|
||||
|
||||
protected abstract Predicate<Tag> extractAttachmentsFilter();
|
||||
|
||||
@@ -11,8 +11,12 @@ import de.srsoftware.cal.api.Coords;
|
||||
import de.srsoftware.tools.Payload;
|
||||
import de.srsoftware.tools.Result;
|
||||
import de.srsoftware.tools.Tag;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
@@ -75,6 +79,14 @@ public class Util {
|
||||
return String.join("\r\n",lines);
|
||||
}
|
||||
|
||||
public static void dump(Tag tag){
|
||||
try {
|
||||
Files.writeString(Path.of("/tmp/dump.txt"),tag.toString(4));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static Result<Coords> extractCoords(String coords) {
|
||||
if (coords == null) return error("Argument is null");
|
||||
if (coords.isBlank()) return error("Argument is blank");
|
||||
@@ -197,6 +209,14 @@ public class Util {
|
||||
}
|
||||
}
|
||||
|
||||
public static Result<Integer> parseInt(String s){
|
||||
try {
|
||||
return Payload.of(Integer.parseInt(s));
|
||||
} catch (NumberFormatException e){
|
||||
return error(e,"Failed to parse %s as integer!",s);
|
||||
}
|
||||
}
|
||||
|
||||
public static Result<URL> url(Result<String> urlResult) {
|
||||
if (urlResult.optional().isEmpty()) return transform(urlResult);
|
||||
var url = urlResult.optional().get();
|
||||
|
||||
Reference in New Issue
Block a user