User Tools

Site Tools


Matrix bot task: Celtic game warning

I want to know if the pub is gonna be busy or if certain friends might not be available, so I need to know when Celtic games are on.

The first hit when I searched 'celtic games' was this Sky Sports: Celtic Fixtures page. Luckily they provide an iCal feed of the games. I used the Sabre VObject PHP class to parse their calendar file.

Install VObject using composer:

cd projectdir
composer require sabre/vobject ~4.1
use Sabre\VObject;
include  'vendor/autoload.php';
$url = "";
$vcalendar = VObject\Reader::read(fopen($url, 'r'));
$today = date("Ymd");
$str = "";
foreach($vcalendar->VEVENT as $event) {
   $date = substr($event->DTSTART,0,8);
   if($today == $date) {
      $time = substr($event->DTSTART,8,12);
      $str .= "Warning:  Celtic game today at ";
      $str .= date("g:ia", strtotime($time));
      $str .= " (";
      $str .= $event->SUMMARY;
      $str .= ")";
      $str .= "\n";
if(!empty($str)) {
   $mat = new matrix();
   $room = "#glasgow";
   $mat->post($str, $room);

That runs once a day, in the morning and warns me in the main #glasgow channel. It uses my Matrix PHP class to post.

celtic_game.txt · Last modified: 2020/12/20 17:19 by admin