User Tools

Site Tools


celtic_game

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
celtic-warning.php
<?php
use Sabre\VObject;
include  'vendor/autoload.php';
 
$url = "https://www.skysports.com/calendars/football/fixtures/teams/celtic?live=false";
$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)) {
 
   require("matrix.class.php");
   $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