summaryrefslogtreecommitdiffabout
path: root/doc
Unidiff
Diffstat (limited to 'doc') (more/less context) (ignore whitespace changes)
-rw-r--r--doc/tag-photo.bash6
1 files changed, 3 insertions, 3 deletions
diff --git a/doc/tag-photo.bash b/doc/tag-photo.bash
index 83f10fd..5917f12 100644
--- a/doc/tag-photo.bash
+++ b/doc/tag-photo.bash
@@ -1,53 +1,53 @@
1#!/bin/bash 1#!/bin/bash
2JPG="$1" 2JPG="$1"
3LOG="$2" 3LOG="$2"
4 4
5( type sqlite3 && type xmlstarlet && type exiftool && type gawk && type curl ) &>/dev/null \ 5( type sqlite3 && type xmlstarlet && type exiftool && type gawk && type curl ) &>/dev/null \
6|| { echo "couldn't find something useful" ; exit 1 ; } 6|| { echo "couldn't find something useful" ; exit 1 ; }
7 7
8[[ -z "$WPS_U" ]] && WPS_U="*PUT_ME_HERE*" 8[[ -z "$WPS_U" ]] && WPS_U="*PUT_ME_HERE*"
9[[ -z "$WPS_R" ]] && WPS_R="*PUT_ME_HERE*" 9[[ -z "$WPS_R" ]] && WPS_R="*PUT_ME_HERE*"
10[[ -z "$LCACHE" ]] && LCACHE="/tmp/iii-locations-cache.sqlite" 10[[ -z "$LCACHE" ]] && LCACHE="/tmp/iii-locations-cache.sqlite"
11wps_locate() { 11wps_locate() {
12 local APS="$1" 12 local APS="$1"
13 [[ -z "$APS" ]] && return; 13 [[ -z "$APS" ]] && return;
14 local APSKEY="$(md5sum <<<"$APS"|gawk -- '{print $1}')" 14 local APSKEY="$(md5sum <<<"$APS"|gawk -- '{print $1}')"
15 local RV="" 15 local RV=""
16 [[ -r "$LCACHE" ]] \ 16 [[ -r "$LCACHE" ]] \
17 && RV="$(sqlite3 "$LCACHE" "SELECT v FROM lc WHERE k='$APSKEY'")" \ 17 && RV="$(sqlite3 "$LCACHE" "SELECT v FROM lc WHERE k='$APSKEY'")" \
18 || sqlite3 "$LCACHE" 'CREATE TABLE lc ( k varchar PRIMARY KEY, v varchar )' 18 || sqlite3 "$LCACHE" 'CREATE TABLE lc ( k varchar PRIMARY KEY, v varchar )'
19 [[ -z "$RV" ]] || { echo "$RV" ; return 0 ; } 19 [[ -z "$RV" ]] || { echo "$RV" ; return 0 ; }
20 X="$(curl -s -H 'Content-Type: text/xml' -d "<?xml version='1.0'?><LocationRQ xmlns='http://skyhookwireless.com/wps/2005' version='2.6' street-address-lookup='none'><authentication version='2.0'><simple><username>$WPS_U</username><realm>$WPS_R</realm></simple></authentication>$APS</LocationRQ>" https://api.skyhookwireless.com/wps2/location)" 20 X="$(curl -s -H 'Content-Type: text/xml' -d "<?xml version='1.0'?><LocationRQ xmlns='http://skyhookwireless.com/wps/2005' version='2.6' street-address-lookup='none'><authentication version='2.0'><simple><username>$WPS_U</username><realm>$WPS_R</realm></simple></authentication>$APS</LocationRQ>" https://api.skyhookwireless.com/wps2/location)"
21 RV="$(xmlstarlet sel -N w=http://skyhookwireless.com/wps/2005 -t -m '/w:LocationRS/w:location/*' -o wl_ -v 'name()' -o '=' -v 'text()' -o ' ' - <<<"$X")" 21 RV="$(xmlstarlet sel -N w=http://skyhookwireless.com/wps/2005 -t -m '/w:LocationRS/w:location/*' -o wl_ -v 'name()' -o '=' -v 'text()' -o ' ' - <<<"$X")"
22 sqlite3 "$LCACHE" "INSERT INTO lc (k,v) VALUES ('$APSKEY','$RV')" &>/dev/null 22 sqlite3 "$LCACHE" "INSERT INTO lc (k,v) VALUES ('$APSKEY','$RV')" &>/dev/null
23 echo "$RV" 23 echo "$RV"
24 return 0 24 return 0
25} 25}
26 26
27ts="$(TZ=UTC date +%s -d "$(exiftime -tc "$JPG"|cut -d\ -f3-|sed -e s/:/-/ -e s/:/-/)")" 27ts="$(TZ=UTC date +%s -d "$(exiftime -tc "$JPG"|cut -d\ -f3-|sed -e s/:/-/ -e s/:/-/)")"
28APS="$(gawk <"$LOG" -F, -v ts="$ts" -- ' 28APS="$(gawk <"$LOG" -F, -v ts="$ts" -- '
29BEGIN { nap=0; } 29BEGIN { nap=0; }
30$3=="NEWPHOTO" && $2>ts { pdt=$1; nextfile; } 30$3=="NEWPHOTO" && $2>ts { pdt=$1; nextfile; }
31$3=="AP" || $3=="NEWAP" { 31$3=="AP" || $3=="NEWAP" {
32 n = ($4 in ap) ? ap[$4] : nap; 32 n = ($4 in ap) ? ap[$4] : nap;
33 ap_dt[n] = $1; ap_ap[n]=$4; ap_rssi[n]=$5; 33 ap_dt[n] = $1; ap_ap[n]=$4; ap_rssi[n]=$5;
34 if(n==nap) ap[$4] = nap++; 34 if(n==nap) ap[$4] = nap++;
35} 35}
36$3=="POWERON" { nap=0; delete ap_dt; delete ap_ap; delete ap_rssi; delete ap; } 36$3=="POWERON" { nap=0; delete ap_dt; delete ap_ap; delete ap_rssi; delete ap; }
37END { 37END {
38 for(i=0;i<nap;++i) { 38 for(i=0;i<nap;++i) {
39 if((pdt-ap_dt[i])>1800) continue; 39 if((pdt-ap_dt[i])>1800) continue;
40 printf("<access-point><mac>%s</mac><signal-strength>-%d</signal-strength></access-point>\n",ap_ap[i],ap_rssi[i]); 40 printf("<access-point><mac>%s</mac><signal-strength>-%d</signal-strength></access-point>\n",ap_ap[i],ap_rssi[i]);
41 } 41 }
42} 42}
43')" 43')"
44 44
45[[ -z "$APS" ]] && { echo "no access points" ; exit ; } 45[[ -z "$APS" ]] && { echo "no access points" ; return 2>/dev/null || exit ; }
46WL="$(wps_locate "$APS")" 46WL="$(wps_locate "$APS")"
47[[ -z "$WL" ]] && { echo "couldn't find location" ; exit ; } 47[[ -z "$WL" ]] && { echo "couldn't find location" ; return 2>/dev/null || exit ; }
48eval "$WL" 48eval "$WL"
49[[ -z "$wl_latitude" || -z "$wl_longitude" || -z "$wl_hpe" ]] && { echo "invalid location ($WL)"; exit; } 49[[ -z "$wl_latitude" || -z "$wl_longitude" || -z "$wl_hpe" ]] && { echo "invalid location ($WL)"; return 2>/dev/null || exit; }
50[[ "${wl_latitude:0:1}" = '-' ]] && wl_latitude="${wl_latitude:1}" wl_latitude_ref=S || wl_latitude_ref=N 50[[ "${wl_latitude:0:1}" = '-' ]] && wl_latitude="${wl_latitude:1}" wl_latitude_ref=S || wl_latitude_ref=N
51[[ "${wl_longitude:0:1}" = '-' ]] && wl_longitude="${wl_longitude:1}" wl_longitude_ref=W || wl_longitude_ref=E 51[[ "${wl_longitude:0:1}" = '-' ]] && wl_longitude="${wl_longitude:1}" wl_longitude_ref=W || wl_longitude_ref=E
52exiftool -GPSLatitude="$wl_latitude" -GPSLongitude="$wl_longitude" -GPSLatitudeRef=$wl_latitude_ref -GPSLongitudeRef=$wl_longitude_ref -GPSVersionID=0.0.2.2 -GPSProcessingMethod=WLAN "$JPG" 52exiftool -GPSLatitude="$wl_latitude" -GPSLongitude="$wl_longitude" -GPSLatitudeRef=$wl_latitude_ref -GPSLongitudeRef=$wl_longitude_ref -GPSVersionID=0.0.2.2 -GPSProcessingMethod=WLAN "$JPG"
53# XXX: exiftool doesn't like it -GPSHPositioningError="$wl_hpe" 53# XXX: exiftool doesn't like it -GPSHPositioningError="$wl_hpe"