コード例 #1
0
ファイル: index.php プロジェクト: vdurante/TesouroDireto
    // acquire an exclusive lock
    ftruncate($f, 0);
    // truncate file
    $fileMetadata = $dbxClient->getFile("/Tesouro.db", $f);
    fflush($f);
    // flush output before releasing the lock
    flock($f, LOCK_UN);
    // release the lock
} else {
    echo "Couldn't get the lock!";
}
fclose($f);
$results = $db->exec("ATTACH '" . getcwd() . "\\Tesouro.db' as toMerge;\n      BEGIN;\n        insert INTO taxa (titulo_id, valor, timestamp) SELECT titulo_id, valor, timestamp from toMerge.taxa;\n      COMMIT;\n      DETACH toMerge;");
require_once "simple_html_dom.php";
$html = file_get_html('http://www.tesouro.fazenda.gov.br/tesouro-direto-precos-e-taxas-dos-titulos');
$results = $db->query('SELECT * FROM "titulo"');
while ($row = $results->fetchArray()) {
    foreach ($html->find('.listing0') as $e1) {
        if (strpos($e1->innertext, $row['nome']) !== false) {
            $taxa = str_replace(",", ".", $e1->parent()->children(2)->innertext());
            echo $row['id'] . "\t" . $taxa . "<br>";
            $stmt = $db->prepare('INSERT INTO taxa (titulo_id, valor, timestamp) VALUES (:titulo_id, :taxa, :timestamp)');
            $stmt->bindValue(':titulo_id', $row['id'], SQLITE3_INTEGER);
            $stmt->bindValue(':taxa', strval($taxa));
            $stmt->bindValue(':timestamp', time());
            $stmt->execute();
            break;
        }
    }
}
$f = fopen("../db/Tesouro.db", "rb");
コード例 #2
0
ファイル: logic.php プロジェクト: vdurante/TesouroDireto
<?php

//error_reporting(0);
require_once "/db/db.php";
$db = new TesouroDB('db/Tesouro.db');
$r = $db->query("SELECT ti.id, ti.nome, ti.tipo, ti.ano, ti.vencimento, ti.cor, ti.cor_HEX, ta.valor FROM titulo ti INNER JOIN taxa ta ON (ti.id = ta.titulo_id) GROUP BY titulo_id ORDER BY ti.id ASC, ta.timestamp DESC");
while ($row = $r->fetchArray()) {
    $i = $row['id'];
    $titulos[$i]['id'] = $row['id'];
    $titulos[$i]['nome'] = $row['nome'];
    $titulos[$i]['tipo'] = $row['tipo'];
    $titulos[$i]['ano'] = $row['ano'];
    $titulos[$i]['vencimento'] = $row['vencimento'];
    $titulos[$i]['valor'] = $row['valor'];
    $titulos[$i]['cor'] = $row['cor'];
    $titulos[$i]['cor_HEX'] = $row['cor_HEX'];
}
if (isset($titulos[$_GET['id']])) {
    $id = $_GET['id'];
} else {
    $id = 1;
}
$r = $db->query("SELECT * FROM (SELECT * from taxa WHERE titulo_id=" . $id . " ORDER BY timestamp DESC limit 15) order by timestamp ASC");
$i = 0;
while ($row = $r->fetchArray()) {
    //var_dump($row);
    $labels[] = date("Y-m-d", $row['timestamp']);
    $data[] = $row['valor'];
}
function hex2rgba($color, $opacity = false)
{