Skip to content

Instantly share code, notes, and snippets.

@janmoesen
Created November 4, 2020 21:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janmoesen/f324b529dc3ebc6db556372830e6ba08 to your computer and use it in GitHub Desktop.
Save janmoesen/f324b529dc3ebc6db556372830e6ba08 to your computer and use it in GitHub Desktop.
<?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