Created
November 4, 2020 21:05
-
-
Save janmoesen/f324b529dc3ebc6db556372830e6ba08 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Script to Make Afvalophalingskalender Great Again for Ivago (the municipal | |
* waste management company for Ghent, Belgium): | |
* - make events last all day (so they appear on top of the calendar on | |
* Google Calendar, for instance) | |
* - do not use ALL CAPS for event summaries | |
* | |
* 1. Go to https://www.ivago.be/nl/particulier/afval/ophaling | |
* 2. Download the ICS for your street. | |
* 3. Run it through this script. | |
*/ | |
$summaryReplacements = [ | |
'GLAS' => 'Glas', | |
'PAPIER' => 'Papier & karton', | |
'GROFVUIL' => 'Grofvuil (op afroep)', | |
'RESTAFVAL' => 'Restafval', | |
'KERSTBOMEN' => 'Kerstbomen', | |
]; | |
if (empty($_SERVER['argv'][1])) { | |
die("Specify the ICS file downloaded from https://www.ivago.be/nl/particulier/afval/ophaling" . PHP_EOL); | |
} | |
$inputFilename = $_SERVER['argv'][1]; | |
$inputHandle = fopen($inputFilename, 'r') or die("Input file not found: $inputFilename" . PHP_EOL); | |
$outputFilename = basename($inputFilename, '.ics') . '-new.ics'; | |
$outputHandle = fopen($outputFilename, 'wb') or die("Could not open output file: $outputFilename" . PHP_EOL); | |
while (($line = fgets($inputHandle))) { | |
$line = trim($line); | |
if (preg_match('/^DTSTART:(.*)/', $line, $matches)) { | |
$date = new \DateTime($matches[1]); | |
$date->setTimezone(new \DateTimeZone('Europe/Brussels')); | |
$line = 'DTSTART:' . $date->add(new \DateInterval('PT7H'))->format('Ymd'); | |
// Use this if you want the events to start at 07:00 instead. | |
//$date->setTimezone(new \DateTimeZone('UTC')); | |
//$line = 'DTSTART:' . $date->add(new \DateInterval('PT7H'))->format('Ymd\THis\Z'); | |
} else if (preg_match('/^DTEND:/', $line)) { | |
continue; | |
} else if (preg_match('/^SUMMARY:(.*)/', $line, $matches)) { | |
$summary = $matches[1]; | |
$summary = $summaryReplacements[$summary] ?? $summary; | |
$line = "SUMMARY:$summary"; | |
} | |
fputs($outputHandle, "$line\r\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment