public function archiveFile() { if (!class_exists('CommonUtilities')) { include 'src/utilities.php'; } $util = new CommonUtilities(); $origFile = "data/search.json"; $origFile2 = "data/search_full.json"; $newFileName = "data/archive/search-" . $util->getDateTimeNow() . ".json"; $newFileName2 = "data/archive/search_full-" . $util->getDateTimeNow() . ".json"; file_put_contents($newFileName, file_get_contents($origFile), FILE_APPEND); file_put_contents($newFileName2, file_get_contents($origFile2), FILE_APPEND); file_put_contents($origFile, ""); file_put_contents($origFile2, ""); }
public function saveJSONFiles($resultsFull) { $util = new CommonUtilities(); $this->appendFile("data/search_full.json", $resultsFull); $resultsConvert = json_decode(json_encode($resultsFull), true); $resultsSnippet = array(); //Removing the headers and saving the juicy bits foreach ($resultsConvert['results'] as $aSnip) { $jobtitle = $aSnip['jobtitle']; $jobkey = $aSnip['jobkey']; $company = $aSnip['company']; $date = $aSnip['date']; $url = $aSnip['url']; $deleted = (bool) false; $applied = (bool) false; $querydate = $util->getDateTimeNow(); $toapply = array("jobtitle" => $jobtitle, "jobkey" => $jobkey, "company" => $company, "date" => $date, "url" => $url, "deleted" => $deleted, "applied" => $applied, "querydate" => $querydate); $resultsSnippet[] = $toapply; } $this->appendFile("data/search.json", $resultsSnippet); }
public function convertJSONtoCSV($jsonFilename) { if (!class_exists('CommonUtilities')) { include 'src/utilities.php'; } $util = new CommonUtilities(); $csvFilename = "csv/" . $util->getDateTimeNow() . "_search.csv"; $json = file_get_contents($jsonFilename); $array = json_decode($json, true); $f = fopen($csvFilename, 'w'); $firstLineKeys = false; foreach ($array as $line) { if (empty($firstLineKeys)) { $firstLineKeys = array_keys($line); fputcsv($f, $firstLineKeys); $firstLineKeys = array_flip($firstLineKeys); } // Using array_merge is important to maintain the order of keys acording to the first element fputcsv($f, array_merge($firstLineKeys, $line)); } }