Tuši's blog

Tuesday, November 26, 2013


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


Sign on the top with a good advice


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. */


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

$filenamelist  = scandir($input_folder);

echo "Starting script!". PHP_EOL. "Files found: ". count($filenamelist). PHP_EOL;
foreach ($filenamelist as $value) {
$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");
} else {
echo "Files copies: ". $copied_files. PHP_EOL;

No comments:

Post a Comment