-
Notifications
You must be signed in to change notification settings - Fork 0
/
process.php
executable file
·77 lines (60 loc) · 2.3 KB
/
process.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/php
<?php
// Start autoloader
require_once('vendor/autoload.php');
use Monolog\Logger;
use Monolog\Handler\SyslogHandler;
use MichaelArnauts\FileMover\FileMover;
use MichaelArnauts\EyeFiLogParser\EyeFiLogParser;
use MichaelArnauts\GeolocationLookup\GoogleGeolocationLookup;
// Load config
if (!file_exists(__DIR__ . '/config.php')) {
echo "config.php file not found.\n";
exit(1);
}
$config = require_once('config.php');
// Check parameters
if (!isset($argv[1])) {
echo sprintf("Syntax: process.php FILENAME.JPG [FILENAME.JPG.LOG]\n");
exit(1);
}
// Setup logging
$logger = new Logger('eyefi-helper');
$logger->pushHandler(new SyslogHandler('eyefi-helper'));
// Create FileMover
try {
$objFileMover = new FileMover($logger, $argv[1], $config['destination']);
} catch (Exception $ex) {
$logger->error(sprintf("Could not open file: %s\n", $ex->getMessage()));
exit(1);
}
// Geocode when we have a logfile
if (isset($argv[2]) && file_exists($argv[2]) && $config['geocode']) {
try {
// Load Log
$objEyeFiLogParser = new EyeFiLogParser($argv[2]);
$arrEyeFiAccessPoints = $objEyeFiLogParser->GetAccessPoints($objFileMover->getFilename());
if ($arrEyeFiAccessPoints) {
// Convert Access Points
$arrAccessPoints = array();
foreach ($arrEyeFiAccessPoints as $objEyeFiAccessPoint) {
$objAccessPoint = new MichaelArnauts\GeolocationLookup\AccessPoint();
$objAccessPoint->age = $objEyeFiAccessPoint->Age * 1000;
$objAccessPoint->macaddress = $objEyeFiAccessPoint->MacAddress;
$objAccessPoint->snr = intval(log10($objEyeFiAccessPoint->SNR / 100) * 10 - 50);
$arrAccessPoints[] = $objAccessPoint;
}
// Query GPS details
$objGoogleGeolocationLookup = new GoogleGeolocationLookup();
$objLookup = $objGoogleGeolocationLookup->Lookup($arrAccessPoints);
// Set EXIF data
$objFileMover->setCoordinates($objLookup->latitude, $objLookup->longitude);
}
// Remove log file
unlink($argv[2]);
} catch (Exception $ex) {
$logger->error(sprintf("Could not geocode: %s\n", $ex->getMessage()));
}
}
// Move file to destination
$objFileMover->move();