-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbgg_export.php
More file actions
44 lines (33 loc) · 1.19 KB
/
bgg_export.php
File metadata and controls
44 lines (33 loc) · 1.19 KB
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
<?php
// Do a daily export from the BGG Geeklist and export it to a file
// Handy to revert back to old versions of data
// https://www.phpjabbers.com/measuring-php-page-load-time-php17.html
// Timing
$time = microtime();
$time = explode(' ', $time);
$time = $time[1] + $time[0];
$start = $time;
$bgg_list_id = 164572;
// $bgg_list_id = 272582; // Smaller list
$uri = 'https://www.boardgamegeek.com/xmlapi/geeklist/' . $bgg_list_id;
$response = file_get_contents($uri);
$xml = simplexml_load_string($response, "SimpleXMLElement", LIBXML_NOCDATA);
$json = json_encode($xml);
$filePath = realpath(dirname(__FILE__));
$rootPath = realpath($_SERVER['DOCUMENT_ROOT']);
$htmlPath = str_replace($rootPath, '', $filePath);
$file = $htmlPath . '/data/export.txt';
$open = fopen( $file, "w" );
$write = fputs( $open, $json );
fclose( $open );
$array = json_decode($json,TRUE);
// Timing
$time = microtime();
$time = explode(' ', $time);
$time = $time[1] + $time[0];
$finish = $time;
$total_time = round(($finish - $start), 4);
date_default_timezone_set('Australia/Melbourne');
echo "===============================\n";
echo "Updated: " . date("Y-m-d H:i:s") . "\n";
echo "Execution Time: " . $total_time . " seconds\n";