Beispiel #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++) {
Beispiel #2
0
$doc = parse('http://www.cpubenchmark.net/cpu_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 < 2000) {
        continue;
    }
    $price = str_replace('$', '', $price);
    $price = str_replace(',', '', $price);
    $price = str_replace('*', '', $price);
    if ($price == 'NA') {
        continue;
    }
    $result = parseCpuByName($name);
    if (!$result) {
        continue;
    }
    $brand = $result['brand'];
    $cat = $result['cat'];
    $tier = $result['tier'];
    $model = $result['model'];
    $freq = $result['freq'];
    $socket = getCpuSocket($model);
    if (!$socket) {
        continue;
    }
    $name = "{$brand} {$cat} {$tier}-{$model}";
    if (!sql("INSERT INTO cpu(name, freq, socket, score, price) VALUES ('{$name}', {$freq}, '{$socket}', {$score}, {$price})", 0, 0)) {
        sql("UPDATE cpu SET freq = {$freq}, socket = '{$socket}', score = {$score}, price = {$price} WHERE name = '{$name}'");