GoogleMapsの衛星写真を使ってあの国を監視してみた。

GoogleMapsの衛星写真を使ってあの国を監視するレシピを考えました。間にシェルを挟んでいるのでちょっと反則ですが ><

監視方法

以下の手順で危険をメールで通知します。
plagger -c browser.yaml→capture.sh→plagger -c warning.yaml

  1. GoogleMapsで画像をキャプチャ(browser.yaml)
  2. 前回のキャプチャ画像と比較(capture.sh)
  3. 変化なし→安全→何もなし
  4. 変化あり!→ミサイル準備?車両集結?→危険をメールで通知(warning.yaml)


画像をキャプチャ(browser.yaml)


画像の比較(capture.sh)

  • ImageMagickのidentifyで画像情報を取得し比較します。画像サイズに変化があれば衛星写真に何らかの変化が起きたと考えられます。
site.png PNG 1280x800 1280x800+0+0 DirectClass 1.674mb 

危険をメールで通知(warning.yaml)

  • 画像に変化が生じた場合、縮小した画像をメールに添付し送信します。

レシピ

plugins:
 - module: CustomFeed::Debug
   config:
     title: BrowserCapture
     entry:
       - title: map
         link: http://maps.google.co.jp/maps?f=q&hl=ja&q=%E5%B9%B3%E5%A3%8C&ie=UTF8&z=15&ll=39.032319,125.754039&spn=0.018435,0.045147&t=k&om=1
 - module: Publish::Pipe
   config:
     command: /Users/akihito/plagger/browser/capture.sh &
 - module: Notify::OpenBrowser
  • capture.sh
#!/bin/sh

sleep 15

size1=`identify /Users/akihito/plagger/site.png`
screencapture /Users/akihito/plagger/site.png
size2=`identify /Users/akihito/plagger/site.png`

d=`date '+%Y-%m-%d %H:%M:%S'`

if [ "$size1" = "$size2" ]; then
    echo "$d No Crisis : Democratic People's Republic of Korea" >> /Users/akihito/plagger/monitor.log
else
    convert -geometry 30% /Users/akihito/plagger/browser/site.png /Users/akihito/plagger/monitor.jpg
    echo "$d Warning : Democratic People's Republic of Korea" >> /Users/akihito/plagger/monitor.log
    plagger -c /Users/akihito/plagger/warning.yaml
fi
plugins:
 - module: CustomFeed::Debug
   config:
     title: Monitor DPRK
     entry:
       - title: Warning Democratic People's Republic of Korea
         link: http://maps.google.co.jp/maps?f=q&hl=ja&q=%E5%B9%B3%E5%A3%8C&ie=UTF8&z=15&ll=39.032319,125.754039&spn=0.018435,0.045147&t=k&om=1
         body: Crisis Condition
         enclosure:
           - url: file:/Users/akihito/plagger/monitor.jpg
             filename: map.jpg
             type: image/jpeg
 - module: Filter::FindEnclosures
 - module: Filter::FetchEnclosure
   config:
     dir: /Users/akihito/plagger/tmp
 - module: Publish::Gmail
   config:
     attach_enclosures: 1
     mailto: example@gmail.com
     mailfrom: example@gmail.com
     mailroute:
       via: smtp
       host: smtp.host

実際は

衛星写真は頻繁に更新されるものではなく最近の写真でもないので、現時点では無意味なレシピです(;。将来的に衛星写真がリアルルタイムで反映されるようになるとネタではなくなるかもしれません(時刻により写真の明るさも変わるので危険な物体だけの差分は難しいよなぁ。せいぜい写真データが更新された事が分かるぐらいでしょうか。)あとマーカー等は地図に無い方が良いですね、マーカーの陰に物体が隠れる可能性があるので....。

シェルの中で判断させないで、ありもののPluginとyamlだけで書きたかったのですが.....
うーんやり方あるのかな。

追記:うはっ!

Kansai.pmで早速ネタにされてました。みんなさん喜んでいただけましたでしょうか?