hardcode profile ids for inno clan
[sc2-widget] / widget.php
index eec063774ea0932f227c4d48f5f02f935a82a49d..78f0ab28ef564b6f2fcd70a40b8581fbb6aa11fc 100644 (file)
@@ -18,13 +18,30 @@ function error($message, $status = 500)
 }
 
 $request = trim($_SERVER['PATH_INFO'], '/');
-if (!file_exists("$request.json")) {
-       if (!is_numeric($request)) {
+$target = "data/$request.json";
+$last = file_exists($target) ? filemtime($target) : 0;
+
+if ($last < time() - 3600) {
+       $recipe = NULL;
+       if (is_numeric($request)) {
+               $recipe = $request;
+       }
+       elseif ($request == 'inno') {
+               #TODO: get ids from existing data
+               $recipe = "$request 2138280 6531490";
+       }
+       elseif (!$last) {
                error("Unknown profile request <q>$request</q>", 400);
        }
-       system("./getsc2clan $request | sponge $request.json", $exitcode);
-       if ($exitcode) {
-               error("No results for profile id $request from Blizzard", 503);
+
+       if ($recipe) {
+               system("./getsc2clan $recipe | sponge $target", $exitcode);
+               if ($exitcode and !$last) {
+                       error("No results for profile $request from Blizzard", 503);
+               }
        }
 }
+if (!filesize($target)) {
+       error("No clan data for <q>$request</q>", 404);
+}
 require('widget.html');