forked from thorgrin/beerlist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
59 lines (50 loc) · 1.17 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
putenv('LANG=en_US.UTF-8');
$output = "";
if (!isset($_GET['p'])){
$bar = 'all';
} else {
$bar = $_GET['p'];
}
switch ($bar) {
case 'mw':
case 'op':
case 'craft':
case 'jbm':
case 'fa':
$update = "./tools/update_cache.sh ".$bar;
$file = "cache/".$bar.".json";
break;
case 'all':
$update = "";
$file = 'cache/op.json cache/mw.json cache/craft.json cache/jbm.json cache/fa.json';
break;
case 'history':
die("<pre>".shell_exec("(cat ./log/beerlog.json | ./tools/log2table.py)")."</pre>");
break;
default:
die("'mw', 'op', 'craft', 'all' or 'history'\n");
}
// Handle caching
if (!empty($update)) {
$modtime = filemtime($file);
$curtime = time();
if ($curtime > $modtime + 300) {
shell_exec($update);
}
}
// Read cached file(s)
$output = shell_exec("(cat ".$file." | ./tools/json2table.py)");
$titles = shell_exec("(cat ".$file." | ./tools/json2titles.py)");
// For browsers
if (stripos($_SERVER['HTTP_USER_AGENT'], "Mozilla") !== false) {
print "<head><title>".$titles."</title></head>\n";
$output = "<pre>".$output."</pre>";
}
// Short version for IRC
if (isset($_GET['t']) && $_GET['t'] == "irc") {
print($titles);
} else {
print($output);
}
?>