Rewrite the schedule generation script #31

Merged
user890104 merged 19 commits from schedule-rewrite into master 2016-10-24 00:52:04 +03:00
5 changed files with 74 additions and 78 deletions
Showing only changes of commit 439d778f15 - Show all commits

View File

@ -71,17 +71,16 @@ class SmartCurl {
} }
if (curl_setopt($this->ch, CURLOPT_URL, $url) === false) { if (curl_setopt($this->ch, CURLOPT_URL, $url) === false) {
throw new Exception('set url failed'); throw new Exception('set url failed: ' . $url);
} }
$cache_file = $this->cache_dir . DIRECTORY_SEPARATOR . $filename; $cache_file = $this->cache_dir . DIRECTORY_SEPARATOR . str_replace('/', '@', $filename);
$etag = array_key_exists($url, static::$etags) && file_exists($cache_file) ? static::$etags[$url] : null; $etag = array_key_exists($url, static::$etags) && file_exists($cache_file) ? static::$etags[$url] : null;
if (curl_setopt($this->ch, CURLOPT_HTTPHEADER, [ if (curl_setopt($this->ch, CURLOPT_HTTPHEADER, [
'If-None-Match:' . (is_null($etag) ? '' : ' ' . $etag), 'If-None-Match:' . (is_null($etag) ? '' : ' ' . $etag),
]) === false) { ]) === false) {
throw new Exception('set etag failed'); throw new Exception('set etag failed: ' . $url);
} }
$response = curl_exec($this->ch); $response = curl_exec($this->ch);
@ -123,12 +122,6 @@ class SmartCurl {
$body = substr($response, $header_size); $body = substr($response, $header_size);
if ($http_code === 200) { if ($http_code === 200) {
$dirname = dirname($filename);
if ($dirname !== '.') {
mkdir($this->cache_dir . DIRECTORY_SEPARATOR . $dirname, 0777, true);
}
file_put_contents($cache_file, $body); file_put_contents($cache_file, $body);
} }

View File

@ -5,11 +5,28 @@ function getSchedConfig($year = 2015) {
'cfp_url' => 'https://cfp.openfest.org', 'cfp_url' => 'https://cfp.openfest.org',
'cut_len' => 70, 'cut_len' => 70,
]; ];
$config = [ $config = [
2014 => [
'conferenceId' => 1,
'eventTypes' => [
'lecture' => 1,
'workshop' => 2,
],
],
2015 => [ 2015 => [
'allowedHallIds' => [6, 7, 8], 'conferenceId' => 2,
'eventTypes' => [
'lecture' => 3,
'workshop' => 4,
],
],
2016 => [
'conferenceId' => 3,
'eventTypes' => [
'lecture' => 5,
'workshop' => 6,
],
], ],
]; ];

View File

@ -43,24 +43,14 @@ foreach ($content['lines'] as $line) {
<table border="1"> <table border="1">
<tbody> <tbody>
<?php <?php
foreach ($content['legend'] as $line) { echo $content['legend'], PHP_EOL;
echo $line, PHP_EOL;
}
?> ?>
</tbody> </tbody>
</table> </table>
<?php <?php
foreach ($content['fulltalks'] as $line) { echo $content['fulltalks'];
echo $line, PHP_EOL; echo $content['gspk'];
} echo $content['fspk'];
foreach ($content['gspk'] as $line) {
echo $line, PHP_EOL;
}
foreach ($content['fspk'] as $line) {
echo $line, PHP_EOL;
}
?> ?>
</body> </body>
</html> </html>

View File

@ -7,8 +7,6 @@ function compareKeys($a, $b, $key) {
} }
function loadData($config) { function loadData($config) {
$base_url = $config['cfp_url'] . '/api/conferences/2/';
$filenames = [ $filenames = [
'events' => 'events.json', 'events' => 'events.json',
'speakers' => 'speakers.json', 'speakers' => 'speakers.json',
@ -19,10 +17,10 @@ function loadData($config) {
]; ];
$data = []; $data = [];
$curl = new SmartCurl($config['cfp_url'] . '/api/conferences/');
foreach ($filenames as $name => $filename) { foreach ($filenames as $name => $filename) {
$curl = new SmartCurl($base_url); $json = $curl->getUrl($config['conferenceId'] . '/' . $filename);
$json = $curl->getUrl($filename);
if ($json === false) { if ($json === false) {
echo 'get failed: ', $filename, PHP_EOL; echo 'get failed: ', $filename, PHP_EOL;
@ -62,9 +60,5 @@ function loadData($config) {
return compareKeys($a, $b, 'starts_at') ?: compareKeys($a, $b, 'hall_id'); return compareKeys($a, $b, 'starts_at') ?: compareKeys($a, $b, 'hall_id');
}); });
$data['halls'] = array_filter($data['halls'], function($key) use ($config) {
return in_array($key, $config['allowedHallIds']);
}, ARRAY_FILTER_USE_KEY);
return $data; return $data;
} }

View File

@ -3,7 +3,7 @@ function parseData($config, $data) {
$time = 0; $time = 0;
$date = 0; $date = 0;
$lines = []; $lines = [];
$fulltalks = []; $fulltalks = '';
$prev_event_id = 0; $prev_event_id = 0;
$colspan = 1; $colspan = 1;
@ -22,11 +22,7 @@ function parseData($config, $data) {
date_default_timezone_set('Europe/Sofia'); date_default_timezone_set('Europe/Sofia');
setlocale(LC_TIME, $languages[$config['lang']]['locale']); setlocale(LC_TIME, $languages[$config['lang']]['locale']);
foreach ($data['slots'] as $slot_id => $slot) { foreach ($data['slots'] as $slot) {
if (!in_array($slot['hall_id'], $config['allowedHallIds'])) {
continue;
}
$slotTime = $slot['starts_at']; $slotTime = $slot['starts_at'];
$slotDate = date('d', $slotTime); $slotDate = date('d', $slotTime);
@ -77,7 +73,7 @@ function parseData($config, $data) {
} else { } else {
/* TODO: fix the URL */ /* TODO: fix the URL */
$name = $data['speakers'][$uid]['first_name'] . ' ' . $data['speakers'][$uid]['last_name']; $name = $data['speakers'][$uid]['first_name'] . ' ' . $data['speakers'][$uid]['last_name'];
$spk[$uid] = '<a class="vt-p" href="SPKURL#'. $name . '">' . $name . '</a>'; $spk[$uid] = '<a class="vt-p" href="#'. $name . '">' . $name . '</a>';
} }
} }
$speakers = implode (', ', $spk); $speakers = implode (', ', $spk);
@ -86,9 +82,9 @@ function parseData($config, $data) {
/* Hack, we don't want language for the misc track. This is the same for all years. */ /* Hack, we don't want language for the misc track. This is the same for all years. */
if ('misc' !== $data['tracks'][$event['track_id']]['name']['en']) { if ('misc' !== $data['tracks'][$event['track_id']]['name']['en']) {
$csslang = "schedule-".$event['language']; $csslang = 'schedule-' . $event['language'];
} else { } else {
$csslang = ""; $csslang = '';
} }
$cssclass = &$data['tracks'][$event['track_id']]['css_class']; $cssclass = &$data['tracks'][$event['track_id']]['css_class'];
$style = ' class="' . $cssclass . ' ' . $csslang . '"'; $style = ' class="' . $cssclass . ' ' . $csslang . '"';
@ -96,13 +92,12 @@ function parseData($config, $data) {
/* these are done by $eid, as otherwise we get some talks more than once (for example the lunch) */ /* these are done by $eid, as otherwise we get some talks more than once (for example the lunch) */
$fulltalks[$eid] = ''; $fulltalks .= '<section id="lecture-' . $eid . '">';
$fulltalks[$eid] .= '<section id="lecture-' . $eid . '">';
/* We don't want '()' when we don't have a speaker name */ /* We don't want '()' when we don't have a speaker name */
$fulltalk_spkr = strlen($speakers)>1 ? ' (' . $speakers . ')' : ''; $fulltalk_spkr = strlen($speakers)>1 ? ' (' . $speakers . ')' : '';
$fulltalks[$eid] .= '<p><strong>' . $event['title'] . ' ' . $fulltalk_spkr . '</strong></p>'; $fulltalks .= '<p><strong>' . $event['title'] . ' ' . $fulltalk_spkr . '</strong></p>';
$fulltalks[$eid] .= '<p>' . $event['abstract'] . '</p>'; $fulltalks .= '<p>' . $event['abstract'] . '</p>';
$fulltalks[$eid] .= '<div class="separator"></div></section>'; $fulltalks .= '<div class="separator"></div></section>';
if ($slot['event_id'] === $prev_event_id) { if ($slot['event_id'] === $prev_event_id) {
array_pop($lines); array_pop($lines);
@ -120,51 +115,58 @@ function parseData($config, $data) {
$lines[] = '</tr>'; $lines[] = '</tr>';
/* create the legend */ /* create the legend */
$legend = []; $legend = '';
foreach($data['tracks'] as $track) { foreach($data['tracks'] as $track) {
$legend[] = '<tr><td class="' . $track['css_class'] . '">' . $track['name'][$config['lang']] . '</td></tr>'; $legend .= '<tr><td class="' . $track['css_class'] . '">' . $track['name'][$config['lang']] . '</td></tr>';
} }
foreach ($languages as $code => $lang) { foreach ($languages as $code => $lang) {
$legend[] = '<tr><td class="schedule-' . $code . '">' . $lang['name'] . '</td></tr>'; $legend .= '<tr><td class="schedule-' . $code . '">' . $lang['name'] . '</td></tr>';
} }
$gspk = []; $gspk = '<div class="grid members">';
$fspk = []; $fspk = '';
$types = []; $types = [
$types['twitter']['url']='https://twitter.com/'; 'twitter' => [
$types['twitter']['class']='fa fa-twitter'; 'class' => 'twitter',
$types['github']['url']='https://github.com/'; 'url' => 'https://twitter.com/',
$types['github']['class']='fa fa-github'; ],
$types['email']['url']='mailto:'; 'github' => [
$types['email']['class']='fa fa-envelope'; 'class' => 'github',
'url' => 'https://github.com/',
$gspk[] = '<div class="grid members">'; ],
'email' => [
'class' => 'envelope',
'url' => 'mailto:',
],
];
foreach ($data['speakers'] as $speaker) { foreach ($data['speakers'] as $speaker) {
$name = $speaker['first_name'] . ' ' . $speaker['last_name']; $name = $speaker['first_name'] . ' ' . $speaker['last_name'];
$gspk[] = '<div class="member col4">'; $gspk .= '<div class="member col4">';
$gspk[] = '<a href="#' . $name . '">'; $gspk .= '<a href="#' . $name . '">';
$gspk[] = '<img width="100" height="100" src="' . $config['cfp_url'] . $speaker['picture']['schedule']['url'].'" class="attachment-100x100 wp-post-image" alt="' . $name .'" />'; $gspk .= '<img width="100" height="100" src="' . $config['cfp_url'] . $speaker['picture']['schedule']['url'].'" class="attachment-100x100 wp-post-image" alt="' . $name .'" />';
$gspk[] = '</a> </div>'; $gspk .= '</a> </div>';
$fspk[] = '<div class="speaker" id="' . $name . '">'; $fspk .= '<div class="speaker" id="' . $name . '">';
$fspk[] = '<img width="100" height="100" src="' . $config['cfp_url'] . $speaker['picture']['schedule']['url'].'" class="attachment-100x100 wp-post-image" alt="' . $name .'" />'; $fspk .= '<img width="100" height="100" src="' . $config['cfp_url'] . $speaker['picture']['schedule']['url'].'" class="attachment-100x100 wp-post-image" alt="' . $name .'" />';
$fspk[] = '<h3>' . $name . '</h3>'; $fspk .= '<h3>' . $name . '</h3>';
$fspk[] = '<div class="icons">'; $fspk .= '<div class="icons">';
foreach ($types as $type => $parm) {
foreach ($types as $type => $param) {
if (!empty($speaker[$type])) { if (!empty($speaker[$type])) {
$fspk[] = '<a href="'. $parm['url'] . $speaker[$type] . '"><i class="' . $parm['class'] . '"></i></a>'; $fspk .= '<a href="' . $param['url'] . $speaker[$type] . '"><i class="fa fa-' . $param['class'] . '"></i></a>';
} }
} }
$fspk[] = '</div>';
$fspk[] = '<p>' . $speaker['biography'] . '</p>'; $fspk .= '</div>';
$fspk[] = '</div><div class="separator"></div>'; $fspk .= '<p>' . $speaker['biography'] . '</p>';
$fspk .= '</div><div class="separator"></div>';
} }
$gspk[] = '</div>'; $gspk .= '</div>';
return compact('lines', 'fulltalks', 'gspk', 'fspk', 'legend'); return compact('lines', 'fulltalks', 'gspk', 'fspk', 'legend');
} }