Updates!!

This commit is contained in:
Christopher Teutsch 2022-12-17 00:10:35 +01:00
parent d170a95469
commit 302d41d09d
3 changed files with 1188 additions and 28 deletions

View File

@ -1,5 +1,7 @@
{ {
"require": { "require": {
"johngrogg/ics-parser": "^2.1.17" "johngrogg/ics-parser": "^3",
"symfony/http-client": "^6.2",
"symfony/http-kernel": "^6.2"
} }
} }

1164
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,9 +1,17 @@
<?php <?php
require_once 'vendor/autoload.php'; require_once 'vendor/autoload.php';
use ICal\ICal; use ICal\ICal;
use Symfony\Component\HttpClient\CachingHttpClient;
use Symfony\Component\HttpClient\HttpClient;
use Symfony\Component\HttpKernel\HttpCache\Store;
$store = new Store('/tmp/dorf.jetzt/');
$client = HttpClient::create();
$client = new CachingHttpClient($client, $store, array('default_ttl' => 60, 'allow_revalidate' => true));
static $DATE_FORMAT = 'd.m.Y H:i'; static $DATE_FORMAT = 'd.m.Y H:i';
static $VISITORS_FILE = '/opt/dorf.jetzt_visitors'; static $VISITORS_FILE = '/opt/dorf.jetzt_visitors';
static $DORF_IN_LOCKDOWN = true; static $DORF_IN_LOCKDOWN = false;
static $DORF_VIRTUAL_EVENTS = true; static $DORF_VIRTUAL_EVENTS = true;
static $ICAL_URL = 'https://chaosdorf.de/~derf/cccd_all.ics'; static $ICAL_URL = 'https://chaosdorf.de/~derf/cccd_all.ics';
$state_map = array( $state_map = array(
@ -50,23 +58,27 @@ $hash_to_state = array(
'0' => 'error', '0' => 'error',
); );
if ($DORF_VIRTUAL_EVENTS || ! $DORF_IN_LOCKDOWN){ if ($DORF_VIRTUAL_EVENTS || ! $DORF_IN_LOCKDOWN){
$img = file_get_contents('https://chaosdorf.de/raumstatus/status.png'); try {
$hash = md5($img); $response = $client->request('GET', 'https://chaosdorf.de/raumstatus/status.png');
$state = $hash_to_state[$hash]; $hash = md5($response->getContent());
$ical = new ICal(false, array( } catch (\Exception $e){
$hash = 0;
}
$state = $hash_to_state[$hash];
$ical = new ICal(false, array(
'defaultSpan' => 2, 'defaultSpan' => 2,
'defaultTimeZone' => 'Europe/Berlin', 'defaultTimeZone' => 'Europe/Berlin',
'defaultWeekStart' => 'MO', 'defaultWeekStart' => 'MO',
'filterDaysBefore' => '1', 'filterDaysBefore' => '1',
)); ));
$ical->initUrl($ICAL_URL, $acceptLanguage = 'de'); $ical->initUrl($ICAL_URL, $acceptLanguage = 'de');
$events = $ical->eventsFromInterval('2 week'); $events = $ical->eventsFromInterval('2 week');
$first_event = $events[0]; $first_event = $events[0];
$events = array_slice($events, 1); $events = array_slice($events, 1);
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){ if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
$locale = locale_accept_from_http($_SERVER['HTTP_ACCEPT_LANGUAGE']); $locale = locale_accept_from_http($_SERVER['HTTP_ACCEPT_LANGUAGE']);
setlocale(LC_TIME, $locale); setlocale(LC_TIME, $locale);
} }
} }
function format_event($event): string{ function format_event($event): string{
global $DATE_FORMAT, $ical; global $DATE_FORMAT, $ical;