Пример #1
0
<?php

require '../lib/libsql.php';
require '../lib/libparser.php';
$name = $_REQUEST['name'];
$length = $_REQUEST['length'];
$cpu = parseCpuByName($name);
$gpu = parseGpuByName($name);
if (!$cpu && !$gpu) {
    die("Invalid CPU / GPU");
}
$result = sql("SELECT * FROM price WHERE name = '{$name}'", 1);
if ($result->num_rows == 0) {
    die("Product not recorded");
}
// Get all price data
$pricelist = [];
while ($row = $result->fetch_assoc()) {
    $date = date_timestamp_get(date_create_from_format('Y-n-j', $row['date']));
    $year = date('Y', $date);
    $doty = date('z', $date);
    $day = ($year - 2013) * 365 + $doty;
    if (!isset($startday)) {
        $startday = $day;
    }
    $price = $row['price'];
    $pricelist[$day] = $price;
}
$endday = $day;
// Calculate missing data
for ($i = $startday; $i <= $endday; $i++) {
Пример #2
0
require '../lib/libsql.php';
require '../lib/libparser.php';
sql('CREATE TABLE IF NOT EXISTS gpu(
	name VARCHAR(255) PRIMARY KEY,
	score INT,
	price DOUBLE
)');
$doc = parse('http://www.videocardbenchmark.net/gpu_list.php');
$rootnode = $doc->getElementById('cputable')->getElementsByTagName('tr');
foreach ($rootnode as $child) {
    $name = $child->firstChild->nodeValue;
    $score = $child->firstChild->nextSibling->nodeValue;
    $price = $child->firstChild->nextSibling->nextSibling->nextSibling->nextSibling->nodeValue;
    if ($score < 500) {
        continue;
    }
    $price = str_replace('$', '', $price);
    $price = str_replace(',', '', $price);
    $price = str_replace('*', '', $price);
    if ($price == 'NA') {
        continue;
    }
    $result = parseGpuByName($name);
    if (!$result) {
        continue;
    }
    if (!sql("INSERT INTO gpu(name, score, price) VALUES ('{$name}', {$score}, {$price})", 0, 0)) {
        sql("UPDATE gpu SET score = {$score}, price = {$price} WHERE name = 'name'");
    }
    echo "{$name} {$score} {$price}<br>";
}