FicIcsTimestamps - konvertiert Export aus Google Kalender für Import in

Nextcloud
This commit is contained in:
2020-09-15 14:21:45 +02:00
parent dc879ed593
commit 23af8f58bc
@@ -0,0 +1,157 @@
package de.tilman.scripting;
import java.io.BufferedReader;
import java.io.FileReader;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/*
#41237 - Chor montags 17:30 ==> lokale Zeitzone, Zielformat
BEGIN:VEVENT
DTSTART;TZID=Europe/Berlin:20200914T173000
DTEND;TZID=Europe/Berlin:20200914T183000
RRULE:FREQ=WEEKLY;WKST=MO;UNTIL=20210621T215959Z;BYDAY=MO
DTSTAMP:20200914T174410Z
UID:6hijie346lh3ib9p6pim6b9k75im2bb2c8rj0bb360q68d9h6gqjed9k6c@google.com
CREATED:20200911T140024Z
DESCRIPTION:<font color="#FB8C00">●</font>
LAST-MODIFIED:20200911T140024Z
LOCATION:Hardenbergstraße 33
SEQUENCE:0
STATUS:CONFIRMED
SUMMARY:Anton Staats- und Domchor Probe
TRANSP:OPAQUE
END:VEVENT
#36351 Elternabend Jacob 11.3. 17:00-19:00 (Winterzeit) ==> muss konvertiert werden
BEGIN:VEVENT
DTSTART:20200311T160000Z
DTEND:20200311T180000Z
DTSTAMP:20200914T174410Z
UID:hrkrr1f67h1a38abhruogfjucdcdvoa03mm9187a22161l95ppftu64u8s@google.com
CREATED:20200106T155150Z
DESCRIPTION:<font color="#FB8C00">●</font>
LAST-MODIFIED:20200106T155151Z
LOCATION:
SEQUENCE:0
STATUS:CONFIRMED
SUMMARY:Elternabend Jacob
TRANSP:OPAQUE
END:VEVENT
#43692 Geburtstag Moritz 2.10. 14:45-18:30 (Sommerzeit) ==> muss konvertiert werden
BEGIN:VEVENT
DTSTART:20201002T124500Z
DTEND:20201002T163000Z
DTSTAMP:20200914T174410Z
UID:svt4q8rt5go36p78rkmtmu3gcs82t82bi5druln2hpq8tp1ldj96m2ea2h@google.com
CREATED:20200914T141118Z
DESCRIPTION:<font color="#FB8C00">●</font>
LAST-MODIFIED:20200914T141119Z
LOCATION:Dockx 3D Schwarzlicht Minigolf\nOrdensmeisterstr. 1-3
SEQUENCE:0
STATUS:CONFIRMED
SUMMARY:Kindergeburtstag Moritz (Anton)
TRANSP:OPAQUE
END:VEVENT
*/
public class FixIcsTimestamps {
private final static Logger log = LoggerFactory.getLogger(FixIcsTimestamps.class);
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd'T'HHmmssZ");
String filePath = "/home/tilman/Schreibtisch/00 Temp/2019-10-20 Anica Kalender-Archiv/2020-09-14 Kalender-Backup tilman.liero@gmail.com.ical/Familie_tero23q0dqqfc45r4jjcecl7bs@group.calendar.google.com.ics";
int counter = 0;
int dtval = 0;
int utcEntry = 0;
int tzEntry = 0;
int lineCounter = 1;
public FixIcsTimestamps() {
log.info("Reading file " + filePath);
BufferedReader reader;
List<String> outLines = new ArrayList<String>();
try {
reader = new BufferedReader(new FileReader(filePath));
String line = reader.readLine();
while (line != null) {
if (line.equals("BEGIN:VEVENT")) {
List<String> appointment = new ArrayList<String>();
appointment.add(line);
while (!line.equals("END:VEVENT")) {
line = reader.readLine();
lineCounter++;
if (line.startsWith("DTSTART:")) { // UTC, muss konvertiert werden
utcEntry++;
String startDate = line.substring(8, 24);
Date date = dateFormat.parse(startDate.replaceAll("Z$", "+0000"));
String convertedStartDate = "DTSTART;TZID=Europe/Berlin:" + dateFormat.format(date).substring(0,15);
appointment.add(convertedStartDate);
log.info("input " + line + ", converted: " + convertedStartDate);
} else if (line.startsWith("DTEND:")) { // UTC, muss konvertiert werden
String endDate = line.substring(6, 22);
Date date = dateFormat.parse(endDate.replaceAll("Z$", "+0000"));
String convertedEndDate = "DTEND;TZID=Europe/Berlin:" + dateFormat.format(date).substring(0,15);
appointment.add(convertedEndDate);
} else { // no conversion
if (line.startsWith("DTSTART;VALUE=DATE:")) { // ganztägiger Termin
dtval++;
} else if (line.startsWith("DTSTART;TZID=")) { // Local Timezone
tzEntry++;
}
appointment.add(line);
}
}
outLines.addAll(appointment);
counter++;
}
else {
outLines.add(line);
}
line = reader.readLine();
lineCounter++;
}
reader.close();
} catch (Exception e) {
e.printStackTrace();
}
log.info("Counter: " + counter);
log.info("DTVAL: " + dtval);
log.info("UTC: " + utcEntry);
log.info("TZ: " + tzEntry);
log.info("DTVAL + UTC + TZ = " + (dtval + utcEntry + tzEntry));
for (String line : outLines) {
System.out.println(line);
}
}
public static void main(String[] args) {
new FixIcsTimestamps();
}
}