forked from super3/primecoin.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_records.php
45 lines (40 loc) · 1.29 KB
/
update_records.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
require('include/simple_html_dom.php');
// Configuration values
define('DATA_PATH', 'records.txt');
define('INFO_EXPIRY', 90); // Seconds before cached data is re-downloaded
ini_set( 'default_socket_timeout', 120 );
set_time_limit( 120 );
function fetch_records() {
echo '<p>Fetch Primecoin records from https://primes.zone/api.php?get=records...</p>';
$data = json_decode(file_get_contents('https://primes.zone/api.php?get=records'));
$records = array();
foreach ($data as $rawrecord) {
$type = $rawrecord[0];
$typeReadable = '';
switch ($type) {
case "1CC":
$typeReadable = "Cunningham Chain of the First Kind";
break;
case "2CC":
$typeReadable = "Cunningham Chain of the Second Kind";
break;
case "TWN":
$typeReadable = "Bi-Twin Chain";
break;
}
$record = (object) array('type' => $typeReadable, 'length' => $rawrecord[1], 'origin' => $rawrecord[2], 'block' => $rawrecord[3]);
array_push($records,$record);
}
usort($records, function ($a, $b) {
return ($a -> block) - ($b -> block);
});
return $records;
}
function update_records() {
$info = fetch_records();
file_put_contents(DATA_PATH, json_encode($info));
}
update_records();
echo '*updated*';
?>