コード例 #1
0
    $url = "http://api.blip.pl/tags/bieganie?limit=50&offset={$i}";
    $curlopts = array(CURLOPT_USERAGENT => 'asystent/0.0.1 http://asystent.adblix.pl/', CURLOPT_HTTPHEADER => array('X-Blip-API: 0.02', 'Accept: application/json'), CURLOPT_RETURNTRANSFER => 1, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_0, CURLOPT_CONNECTTIMEOUT => 10, CURLOPT_URL => $url);
    # ustawiamy opcje
    curl_setopt_array($ch, $curlopts);
    $json = curl_exec($ch);
    $HTTP_CODE = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    $obj = json_decode($json);
    print "<h3>HTTP CODE: " . $HTTP_CODE . "</h3>";
    //print "<h3>curl_exec:</h3>";
    // print_r($obj);
    // print "<hr>";
    $regexp = "/#bieganie[\\s]+([0-9]+)([\\.\\,]([0-9]+))*[\\s]*km([\\s]*;[\\s]*([0-9]+:[0-9]+(:[0-9]+)*))*/sim";
    foreach ($obj as $blip) {
        if (preg_match($regexp, $blip->body, $matches)) {
            // print_r($matches);
            if ($duration = getduration($matches)) {
                print "<h3>" . str_replace('/users/', '', $blip->user_path) . ": " . floatval($matches[1] . "." . $matches[3]) . "km on " . $blip->created_at . " [dur. {$duration}]</h3>";
                $runsql = sprintf("INSERT IGNORE INTO bieganie (blip_id, user, distance, rundate, blipsent, duration, bliptxt) VALUES (%d, '%s', %f, '%s', 0, %d, '%s')", $blip->id, str_replace('/users/', '', $blip->user_path), floatval($matches[1] . "." . $matches[3]), $blip->created_at, $duration, mysql_real_escape_string($blip->body));
                // print "<br>$runsql<br>\n";
                mysql_query($runsql);
            } else {
                print "<h3>" . str_replace('/users/', '', $blip->user_path) . ": " . floatval($matches[1] . "." . $matches[3]) . "km on " . $blip->created_at . "</h3>";
                $runsql = sprintf("INSERT IGNORE INTO bieganie (blip_id, user, distance, rundate, blipsent, bliptxt) VALUES (%d, '%s', %f, '%s', 0, '%s')", $blip->id, str_replace('/users/', '', $blip->user_path), floatval($matches[1] . "." . $matches[3]), $blip->created_at, mysql_real_escape_string($blip->body));
                // print "<br>$runsql<br>\n";
                mysql_query($runsql);
            }
        }
    }
}
?>
</pre>
コード例 #2
0
function save_runs($json_messages, $regexp, $debug = false)
{
    global $blocked_users;
    $link = mysql_connect('localhost', 'cardinalpharma', 'tweets');
    if (!$link) {
        die('Nie można się połaczyć: ' . mysql_error());
    }
    $db_selected = mysql_select_db('cardinalpharma', $link);
    if (!$db_selected) {
        die('Nie można ustawić bazy : ' . mysql_error());
    }
    mysql_query("SET character_set_client=utf-8", $link);
    mysql_query("SET character_set_connection=utf-8", $link);
    mysql_query("SET CHARSET utf8", $link);
    mysql_query("SET NAMES 'utf8' COLLATE 'utf8_polish_ci'", $link);
    foreach ($json_messages as $blip) {
        if (in_array($blip->user_path, $blocked_users)) {
            continue;
        }
        // if ($blip->user_path == '/users/biegacze') continue;
        if (preg_match($regexp, $blip->body, $matches)) {
            // print_r($matches);
            if ($duration = getduration($matches)) {
                if ($debug) {
                    print "<h3>" . str_replace('/users/', '', $blip->user_path) . ": " . floatval($matches[1] . "." . $matches[3]) . "km on " . $blip->created_at . " [dur. {$duration}]</h3>";
                }
                $runsql = sprintf("INSERT IGNORE INTO bieganie (blip_id, user, distance, rundate, blipsent, duration, bliptxt) VALUES (%d, '%s', %f, '%s', 0, %d, '%s')", $blip->id, str_replace('/users/', '', $blip->user_path), floatval($matches[1] . "." . $matches[3]), $blip->created_at, $duration, mysql_real_escape_string($blip->body));
                if ($debug) {
                    print "<br>{$runsql}<br>\n";
                }
                mysql_query($runsql);
            } else {
                if ($debug) {
                    print "<h3>" . str_replace('/users/', '', $blip->user_path) . ": " . floatval($matches[1] . "." . $matches[3]) . "km on " . $blip->created_at . "</h3>";
                }
                $runsql = sprintf("INSERT IGNORE INTO bieganie (blip_id, user, distance, rundate, blipsent, bliptxt) VALUES (%d, '%s', %f, '%s', 0, '%s')", $blip->id, str_replace('/users/', '', $blip->user_path), floatval(@$matches[1] . "." . @$matches[3]), $blip->created_at, mysql_real_escape_string($blip->body));
                if ($debug) {
                    print "<br>{$runsql}<br>\n";
                }
                mysql_query($runsql);
            }
        }
    }
}