Graybeard
Well-Known Member
Prologue:
I am gathering stock reports on REIT (Real Estate Investment Trust) shares ( see attached sample ).
I had some errors in this script. Noteworthy, the basic code logic was there, some was mine and some were suggestions from AI prior on this project.

^^ This was to point of the whole exercise --get it done faster --all work is local so internet security is not an issue here.
Bottom line: it's taken me the same time almost to hammer out this post and format the code used
Using AI for this as the assistant coder grunt took me minutes instead of hours fixing things and looking for snippet examples for something I have done but do not do every day.
I could search my own code library for examples that I have used that worked but ChatGPT AI does that work so much faster when you can prompt the right base code or code that is erroring.
I am gathering stock reports on REIT (Real Estate Investment Trust) shares ( see attached sample ).
I had some errors in this script. Noteworthy, the basic code logic was there, some was mine and some were suggestions from AI prior on this project.
- Some of the files I requested with the api were {} empty
- I had the file in the wrong part of the rather complex nested loop
^^ This was to point of the whole exercise --get it done faster --all work is local so internet security is not an issue here.
Bottom line: it's taken me the same time almost to hammer out this post and format the code used
Using AI for this as the assistant coder grunt took me minutes instead of hours fixing things and looking for snippet examples for something I have done but do not do every day.
I could search my own code library for examples that I have used that worked but ChatGPT AI does that work so much faster when you can prompt the right base code or code that is erroring.
PHP:
<?php
$filename = "jason-file-list.csv";
$fileNames = file($filename, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$file = fopen('overview-2023-07-31.csv', 'w'); // Open the file with mode 'w' to clear it before writing
// Loop through the list of file names
foreach ($fileNames as $filename) { // Change $fileName to $filename
$data = file_get_contents($filename); // Change $fileName to $filename
if ($data === false) {
// Handle file reading error
echo "Failed to read file: $filename\n";
continue;
}
$json = json_decode($data, true);
if (!is_array($json)) {
// Handle JSON decoding error
echo "Failed to decode JSON: $filename\n";
continue;
}
foreach ($json as $key => $value) {
if (!is_array($value)) {
echo $value . '|';
} else {
foreach ($value as $val) {
echo $val . '|';
}
}
}
echo "\n\n-------------------\n\n";
foreach ($json as $key => $value) {
if (!is_array($value)) {
echo $key . '|';
} else {
foreach ($value as $val) {
echo $val . '|';
}
}
}
foreach ($json as $key => $value) {
if (!is_array($value)) {
fwrite($file, $value . '|');
}
// Add a new line after each loop iteration
// fwrite($file, "\n");
}
// Close the file handle inside the loop
// No need to close it outside the loop
// fclose($file);
fwrite($file, "\n");
}
// Close the file outside the loop
fclose($file);
?>