Skip to content

Instantly share code, notes, and snippets.

@sharl
Last active December 14, 2016 08:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sharl/9c908a81d9c1ca33c344aad78d75f6ca to your computer and use it in GitHub Desktop.
Save sharl/9c908a81d9c1ca33c344aad78d75f6ca to your computer and use it in GitHub Desktop.
AirPodsを最速で予約する

#ssmjp参加者 Advent Calendar 2016 - Adventar 13日目です。

普段は「どうやったら監視できるか」「どうやったら運用が楽になる監視ができるか」ということを考えながら内製の監視システムを作成しています。

AirPodsを最速で予約する

どーしても発売後すぐ予約したかったので、ふにふにとスクリプトを書いた。

#!/bin/bash

APIKEY=<your pushbullet API key>

FLAG=~/.airpods
TARGET=http://www.apple.com/jp/shop/product/MMEF2J/A/airpods

if [ ! -f ${FLAG} ]; then
   a=$(curl -s ${TARGET} | awk '/product-details-form/{w++} /Currently unavailable/{u++} END{if (w > 0 && u == 0) {print "airpods available"}}')
   if [ -z "$a" ]; then
       : echo airpods unavailable | ~/bin/pushnote ${APIKEY}
   else
       echo ${a} | ~/bin/pushnote ${APIKEY}
       : touch ${FLAG}
   fi
fi

pushnote は PushBullet に通知を送るスクリプト。

#!/usr/bin/env perl
use strict;
use warnings;
use WWW::PushBullet;

my ($apikey, $title, $channel) = @ARGV;
my $body = join('', <STDIN>);
exit unless $body;

my $pb = WWW::PushBullet->new({apikey => $apikey});
$pb->push_note(
    {
        title       => $title,
        body        => $body,
        channel_tag => $channel,
    }
);

こいつで日本時間 2016/12/13 23:00 に AirPods をポチることができました!

なんでも監視しようと思えば監視はできます!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment