-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema-generator.php
More file actions
executable file
·55 lines (46 loc) · 1.42 KB
/
schema-generator.php
File metadata and controls
executable file
·55 lines (46 loc) · 1.42 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
45
46
47
48
49
50
51
52
53
54
55
<?php
/**
* Generate schema.js from the datasets
*
* Usage: php -f schema-generator.php > schema.js
*
*/
$config = file_get_contents("config.js");
preg_match_all('/\{.*\}/sm', $config, $json);
$host = json_decode( $json[0][0] )->host;
$ch = curl_init($host."/api/3/action/package_search?q=*:*&rows=1000");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
$result = curl_exec($ch);
$package_list = json_decode($result)->result->results;
curl_close($ch);
$schema = array();
foreach ($package_list as $package) {
$ch = curl_init($host."/api/3/action/datastore_search?limit=0&id=".$package->resources[0]->id);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = json_decode(curl_exec($ch));
curl_close($ch);
if (!isset($result->result->fields)) {
continue;
}
$schema[$package->resources[0]->id] = array("fields" => $result->result->fields, "title" => $package->title);
}
echo "var schema = ".json_encode($schema, JSON_PRETTY_PRINT);
/*
[23]=>
object(stdClass)#143 (3) {
["info"]=>
object(stdClass)#142 (3) {
["notes"]=>
string(61) "Indicates the weekday associated with the daily metric values"
["type_override"]=>
string(4) "text"
["label"]=>
string(0) ""
}
["type"]=>
string(4) "text"
["id"]=>
string(16) "CTY_SCR_DAY_NAME"
}
*/