Tuši

Tuši's blog

Tuesday, November 26, 2013

12612

Slovenia: Weekly Hike: Gontarska planina and My First PHP script


Our sport and cultural society ŠKD Indijanci went on a fourth morning hike (6th overall). Our destination this time was Gontarska planina, 894 m.

Stamp on the top

Vlado, Grega, Zoki, Rok and me on the top

Sunrise

Sign on the top with a good advice

Moon

Group picture with snowy Kamnik–Savinja Alps in the back

Waterfall without a name known to us on our way down

ŠKD Indijanci - Hike #6

In the evening I wrote my first PHP script. It can be used to copy the files (photos) taken after sunrise and below sunset to a designated folder. It is useful if you download pictures with a script every x minutes and name them correctly.

And the script looks like this:

/* calculate the sunrise time for Kredarica, Slovenia
Latitude: 46.37826 North
Longitude: 13.84901East
Zenith ~= 90
offset: +1 GMT
*/

/*Change input parameters: input_folder, output_folder.
Works on filenames with structure: YYYY*MM*DD*HH*MM?, where * is a single character and ? can be a string. */

$latitude=46.37826;
$longitude=13.84901;
$zenith=90;
$offset=1;
$DATE=date("Y_m_d-H_i");
$copied_files=0;

$input_folder  = "/mnt/storage/private/tomaz_weather_station/fetched_photos";
$output_folder = "/mnt/storage/private/www_photos/Zelenica/out";

$filenamelist  = scandir($input_folder);

//print_r($filenamelist);
echo "Starting script!". PHP_EOL. "Files found: ". count($filenamelist). PHP_EOL;
foreach ($filenamelist as $value) {
$year=substr($value,0,4);
$month=substr($value,5,2);
$day=substr($value,8,2);
$hour=substr($value,11,2);
$minute=substr($value,14,2);
$photo_taken=strtotime("$year-$month-$day $hour:$minute");
$sunrise = date_sunrise(strtotime("$year-$month-$day"), SUNFUNCS_RET_TIMESTAMP, $latitude, $longitude, $zenith, $offset);
$sunset  = date_sunset(strtotime("$year-$month-$day"), SUNFUNCS_RET_TIMESTAMP, $latitude, $longitude, $zenith, $offset);
if ($photo_taken >= $sunrise and $photo_taken <= $sunset) {
copy("$input_folder/$value", "$output_folder/$value");
$copied_files++; 
} else {
}
}
echo "Files copies: ". $copied_files. PHP_EOL;
?>

No comments:

Post a Comment