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": {
"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
require_once 'vendor/autoload.php';
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 $VISITORS_FILE = '/opt/dorf.jetzt_visitors';
static $DORF_IN_LOCKDOWN = true;
static $DORF_IN_LOCKDOWN = false;
static $DORF_VIRTUAL_EVENTS = true;
static $ICAL_URL = 'https://chaosdorf.de/~derf/cccd_all.ics';
$state_map = array(
@ -50,23 +58,27 @@ $hash_to_state = array(
'0' => 'error',
);
if ($DORF_VIRTUAL_EVENTS || ! $DORF_IN_LOCKDOWN){
$img = file_get_contents('https://chaosdorf.de/raumstatus/status.png');
$hash = md5($img);
$state = $hash_to_state[$hash];
$ical = new ICal(false, array(
'defaultSpan' => 2,
'defaultTimeZone' => 'Europe/Berlin',
'defaultWeekStart' => 'MO',
'filterDaysBefore' => '1',
));
$ical->initUrl($ICAL_URL, $acceptLanguage = 'de');
$events = $ical->eventsFromInterval('2 week');
$first_event = $events[0];
$events = array_slice($events, 1);
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
$locale = locale_accept_from_http($_SERVER['HTTP_ACCEPT_LANGUAGE']);
setlocale(LC_TIME, $locale);
}
try {
$response = $client->request('GET', 'https://chaosdorf.de/raumstatus/status.png');
$hash = md5($response->getContent());
} catch (\Exception $e){
$hash = 0;
}
$state = $hash_to_state[$hash];
$ical = new ICal(false, array(
'defaultSpan' => 2,
'defaultTimeZone' => 'Europe/Berlin',
'defaultWeekStart' => 'MO',
'filterDaysBefore' => '1',
));
$ical->initUrl($ICAL_URL, $acceptLanguage = 'de');
$events = $ical->eventsFromInterval('2 week');
$first_event = $events[0];
$events = array_slice($events, 1);
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
$locale = locale_accept_from_http($_SERVER['HTTP_ACCEPT_LANGUAGE']);
setlocale(LC_TIME, $locale);
}
}
function format_event($event): string{
global $DATE_FORMAT, $ical;