From: Andrew Engelbrecht <andrew@fsf.org>
Date: Fri, 18 Mar 2022 00:25:16 +0000 (-0400)
Subject: put all events together in one vcalendar
X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=2d5e73ead501f7558a8c23f16831c448d2c1b3dd;p=lp-csv-to-ics.git

put all events together in one vcalendar
---

diff --git a/generate-ics b/generate-ics
index 5df2f79..2118824 100755
--- a/generate-ics
+++ b/generate-ics
@@ -9,10 +9,19 @@
 //
 // "Saturday","10:00 - 10:15 EDT - Welcome address","Welcome Address by FSF","Jupiter","LibrePlanet special sessions","LibrePlanet  2022","","","http://libreplanet.org/2022/speakers/#5910"
 
+
 include 'ICS.php';
 
 $csv = array_map('str_getcsv', explode("\n", stream_get_contents(STDIN)));
 
+// print out header for vcalendar
+?>BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//FSF//lp-csv-to-ics//EN
+CALSCALE:GREGORIAN
+NAME:LibrePlanet 2022
+<?php
+
 foreach ($csv as $linenum => $line) {
 
     if (count($line) <= 1) {
@@ -54,8 +63,13 @@ foreach ($csv as $linenum => $line) {
         'url' => str_replace("http:", "https:", $line[8]),
     ));
 
-    echo $ics->to_string();
-
-    echo "\n\n";
+    // print the trimmed event string
+    $trimmed_event = array();
+    preg_match("/.*(BEGIN:VEVENT.*END:VEVENT).*/ms", $ics->to_string(), $trimmed_event);
+    echo $trimmed_event[1];
+    echo "\n";
 }
 
+// print out footer for vcalendar
+echo "END:VCALENDAR\r\n";
+