<?php namespace EasyCSV; require_once dirname(dirname(__DIR__)) . '/inc/common.php'; foreach (glob(CKANMNGR_DATA_DIR . '/organizations.json') as $json_file) { $json = json_decode(file_get_contents($json_file), true); // decode as assoc array $basename = str_replace('.json', '', basename($json_file)); $writer = new Writer(CKANMNGR_DATA_DIR . '/' . $basename . '.csv'); // $writer->writeRow([ // 'from', // 'to' // ]); foreach ($json['result'] as $organization) { $writer->writeRow([$organization['name']]); } } // show running time on finish timer();
<?php namespace EasyCSV; require_once dirname(dirname(__DIR__)) . '/inc/common.php'; foreach (glob(CKANMNGR_DATA_DIR . '/de*.json') as $json_file) { $dataset_names = json_decode(file_get_contents($json_file), true); // decode as assoc array $basename = str_replace('.json', '', basename($json_file)); $writer = new Writer(CKANMNGR_DATA_DIR . '/' . $basename . '.csv'); $writer->writeRow(['from', 'to']); foreach ($dataset_names['name'] as $name => $count) { $newName = preg_replace("/^deleted-/", '', $name); $writer->writeRow([$name, $newName]); } } // show running time on finish timer();
// fix wrong END-OF-LINE file_put_contents($csv_file, preg_replace('/[\\r\\n]+/', "\n", file_get_contents($csv_file))); $csv_source = new Reader($csv_file, 'r+', false); $csv_destination = new Writer($results_dir . '/' . $basename . '_long.csv'); $i = 0; while (true) { if (!($i++ % 50)) { echo $i . PHP_EOL; } $row = $csv_source->getRow(); if (!$row) { break; } // skip headers if (in_array(trim(strtolower($row[0])), ['socrata code', 'from'])) { $csv_destination->writeRow($row); continue; } $socrata_id = $row[0]; $ckan_url = $row[1]; // writing short redirect $socrata_short_url = 'https://explore.data.gov/d/' . $socrata_id; $csv_destination->writeRow([$socrata_short_url, $ckan_url]); $socrata_long_url = get_long_socrata_url($curl_ch, $socrata_short_url); if (!$socrata_long_url) { echo 'No result: ' . $socrata_short_url . PHP_EOL; } $csv_destination->writeRow([$socrata_long_url, $ckan_url]); } } /**