function singleRun($method, $params, $file, $nameId)
{
    global $counts;
    $params['count'] = 0;
    $params['offset'] = 0;
    $offset = 0;
    $count = $counts[$method];
    $arr = get($method, $params);
    if (!array_key_exists('response', $arr)) {
        print_r($arr);
        return [];
    }
    $totalCount = $arr['response']['count'];
    if ($totalCount == 0) {
        echo "no items:\t method {$method}\t id {$params[$nameId]}\n";
    }
    while ($offset < $totalCount) {
        $params['count'] = $count;
        $params['offset'] = $offset;
        $arr = get($method, $params);
        if (empty($arr['response']['items'])) {
            continue;
        }
        $res = $arr['response']['items'];
        $offset += $count;
        //$c = count($res);
        $p = [];
        if ($nameId != '') {
            $p = [$nameId => $params[$nameId]];
        }
        writeJson($file, $res, $offset < $totalCount, $p);
        echo "{$method} : {$offset} < {$totalCount}\n";
    }
}
Example #2
0
function addCount($fileName, $id)
{
    $json = readJson($fileName);
    if (empty($json[$id])) {
        $json[$id] = 1;
    } else {
        $json[$id] = $json[$id] + 1;
    }
    writeJson($fileName, $json);
}
function handle_post()
{
    if ($_GET["name"] && $_GET["userid"]) {
        $userName = strtolower(str_replace(' ', '_', $_GET["name"]));
        $filePath = generatePath(strtolower($_GET["userid"]), $userName);
        $json = file_get_contents('php://input');
        writeJson($filePath, $json);
    } else {
        echo generateError("Error while generating / saving");
    }
}
Example #4
0
            $player['tick'] = $tickrate;
            $globalr[$tickrate][] = $player;
        }
    }
    // Same deal as before.
    $playerl = array();
    foreach ($playerlist as $steamid => $player) {
        $player['steamid'] = $steamid;
        $playerl[] = $player;
    }
    // Write players
    foreach ($players as $steamid => $record) {
        // Strip all but numbers from Steam ID
        $id = preg_replace('/[^0-9]/', '', $steamid);
        writeJson('players/' . $id, $players[$steamid]);
    }
    // Calculate 64-bit community IDs for banlist
    for ($i = 0; $i < count($banlist); $i++) {
        $banlist[$i]['comid'] = steamId64($banlist[$i]['steamid']);
    }
    // Write individual maps
    foreach ($maps as $map => $record) {
        writeJson('maps/' . $map, $maps[$map]);
    }
    // Write maplist, globals, player list and latest records
    writeJson('maps', $maplist);
    writeJson('globals', $globalr);
    writeJson('players', $playerl);
    writeJson('latest', $latestrecords);
    writeJson('bans', $banlist);
}
Example #5
0
<?php

require "dbConnect.php";
require "personalFunctions.php";
if (isset($_POST['table']) && isset($_POST['format'])) {
    $sql = 'SELECT * FROM ' . $_POST['table'];
    $result = $dbo->query($sql);
    $rows = $result->fetchAll(PDO::FETCH_ASSOC);
    unset($dbo);
    switch ($_POST['format']) {
        case 'csv':
            writeCsv($rows);
            break;
        case 'json':
            writeJson($rows);
            break;
        case 'xml':
            writeXml($rows);
            break;
    }
} else {
    $result = $dbo->query('SHOW TABLES');
    unset($dbo);
}
/**
 * Marca uma tarefa como concluida
 * @param $id Id da tarefa
 * @return mixed A tarefa modificada, ou false em caso de falha
 */
function taskDone($id)
{
    global $TASKS_DIR;
    $filename = "{$TASKS_DIR}/{$id}.json";
    $task = getTask($id);
    if ($task) {
        $task->concluida = true;
        $task->modificada = date("Y-m-d");
        writeJson($filename, $task);
        return $task;
    }
    return false;
}
Example #7
0
                if (!empty($posts['POST'][$nextIndex])) {
                    $diffMillis = getTimeDiff($posts['POST'][$nextIndex]["TIME"], $post_row["TIME"]);
                    $pair = array("MEAL" => $post_row, "AFTER" => array("POST" => $posts['POST'][$nextIndex], "TIME_DIFF" => $diffMillis));
                    array_push($result, $pair);
                }
            }
        }
        $nextIndex++;
    }
    return writeJson($response, $result);
});
$app->get('/post/{id}', function ($request, $response, $args) use($app, $db) {
    return writeJson($response, $db->getPost($args['id']));
});
$app->get('/users/{id}', function ($request, $response, $args) use($app, $db) {
    return writeJson($response, $db->getUsers($args['id']));
});
function getTimeDiff($from, $to)
{
    $from_date = DateTime::createFromFormat('U', $from);
    $to_date = DateTime::createFromFormat('U', $to);
    $duration = $from_date->diff($to_date);
    $in_time_range = $duration->h <= HOUR_SPAN_LIMIT;
    $milliseconds = $duration->days * 24 * 60;
    $milliseconds += $duration->h * 60;
    $milliseconds += $duration->i;
    $milliseconds *= 60000;
    return $in_time_range ? $milliseconds : 0;
}
function writeJson($response, $array)
{