-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_ckan_packages.php
executable file
·67 lines (54 loc) · 1.64 KB
/
get_ckan_packages.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
set_time_limit(0);
ignore_user_abort(true);
function endsWith($Haystack, $Needle){
return strpos($Haystack, $Needle) === strlen($Haystack)-1;
}
function startsWith($Haystack, $Needle){
return strpos($Haystack, $Needle) === 0;
}
@ini_set('error_reporting', E_ALL);
include_once('Ckan_client-PHP/Ckan_client.php');
$ckan = new Ckan_client();
echo "Fetching dataset list ... ".PHP_EOL;
$group_description = $ckan->get_group_entity('lodcloud');
$package_names = array();
foreach ($group_description->packages as $package_id) {
echo "Adding dataset ";
try {
$package = $ckan->get_package_entity($package_id);
$package_names[] = $package->name;
echo $package->name . PHP_EOL;
} catch (Exception $e) {
try {
$package = $ckan->get_package_entity($package_id);
$package_names[] = $package->name;
echo $package->name . PHP_EOL;
sleep(1);
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), PHP_EOL;
}
}
}
$tag_description = $ckan->get_tag_entity("lod");
echo "";
foreach ($tag_description as $package_id) {
try {
$package = $ckan->get_package_entity($package_id);
if (!in_array($package->name, $package_names)) {
echo "Adding dataset ".$package->name.PHP_EOL;
$package_names[] = $package->name;
}
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), PHP_EOL;
}
}
$fh = fopen('ckan_packages.txt', 'w');
fwrite($fh, '');
fclose($fh);
$fh = fopen('ckan_packages.txt', 'a');
foreach ($package_names as $name) {
fwrite($fh, $name."\n");
}
fclose($fh);
echo "Added ".sizeof($package_names)." packages.";