Exemplo n.º 1
0
 /**
  * @dataProvider getReaders
  */
 public function testOneAtAtime(Reader $reader)
 {
     while ($row = $reader->getRow()) {
         $this->assertTrue($row instanceof Row);
         $this->assertEquals(3, count($row));
     }
 }
curl_setopt($curl_ch, CURLOPT_FILETIME, true);
// Initialize cURL headers
foreach (glob(CKANMNGR_DATA_DIR . '/socrata_*.csv') as $csv_file) {
    $status = PHP_EOL . PHP_EOL . basename($csv_file) . PHP_EOL . PHP_EOL;
    echo $status;
    $basename = str_replace('.csv', '', basename($csv_file));
    //    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) {