30
22

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Amazon Dash Buttonで何も考えずにいろいろ遊ぶ

Last updated at Posted at 2016-12-10

なにも考えずにいろいろします
この記事の前に、環境設定の参考として下記事に目を通すことをオススメします
Amazon Dash Buttonを(正しくない方向で)使ってみた

環境

macOS Sierra 10.12.1、node v7.2.0で書いています。

準備:ありがたいライブラリ
$ npm install dash-button

パソコンがへぇーっていう

へぇ

trivia.js
const DashButton = require('dash-button');
const {exec} = require('child_process');
const button = new DashButton("xx:xx:xx:xx:xx:xx");
button.addListener(exec('say -v Kyoko "へぇえええーー"'));

適当な音楽を鳴らす

ゲットワイルドな退勤

getwild.js
const DashButton = require('dash-button');
const {exec} = require('child_process');
const button = new DashButton("xx:xx:xx:xx:xx:xx");
const player = (process.platform === 'darwin') ? 'afplay' : 'aplay';
button.addListener(() => exec(`${player} ./get_wild.mp3`));

松屋のメニューを言う

今日の晩ごはんを決めれる

準備

$ gem install matsuya
matsuya.js
const DashButton = require('dash-button');
const {exec} = require('child_process');
const button = new DashButton("xx:xx:xx:xx:xx:xx");
button.addListener(() => exec(`say -v Kyoko "今日の晩ごはんは$(matsuya)"`));

腕立て伏せのカウントをする

あご、つければいける

udetate.js
const DashButton = require('dash-button');
const {exec} = require('child_process');
const button = new DashButton("xx:xx:xx:xx:xx:xx");
let count = 0;
button.addListener(() => exec(`say -v Kyoko "腕立て${++count}回目"`));

社長に電話かけてボーナスを要求する

もらえた試しがありません。

Twilio使います

$ npm install twilio querystring
bonasu-hoshii.js
const querystring = require('querystring');
const DashButton = require('dash-button');
const twilio = require('twilio');
const client = twilio('accountsid', 'authtoken');
const button = new DashButton("xx:xx:xx:xx:xx:xx");

button.addListener(() => {
  client.makeCall({
    to: '+81XXXXXXXXXX',
    from: '+81XXXXXXXXXX',
    url: 'http://twimlets.com/echo?Twiml=' + querystring.escape('<Response><Say voice="woman" language="ja-jp">今年こそ賞与が欲しいです。</Say></Response>')
  }, (e) => console.warn(e));
});

今日の警報を気象庁から引っ張って来て鳴らす

出かける前にチェックしよう

$ npm install dateformat
keiho.js
const DashButton = require('dash-button');
const button = new DashButton("xx:xx:xx:xx:xx:xx");
const {exec,execSync} = require('child_process');
const dateFormat = require('dateformat');

button.addListener(() => {
  const today = dateFormat(new Date(), 'yyyy-mm-dd%2000:00:00');
  const now = dateFormat(new Date(), 'yyyy-mm-dd%20hh:MM:ss');
  const area = execSync(`curl -s 'http://api.aitc.jp/jmardb-api/area?longitude=139.7512247&latitude=35.6199114' -H 'Accept: application/json'`);
  const areaData = JSON.parse(area.toString());
  const bosai = execSync(`curl -s 'http://api.aitc.jp/jmardb-api/search?datetime=${today}&datetime=${now}&areacode=${areaData.data[0].code}'`);
  const bosaiData = JSON.parse(bosai.toString());
  bosaiData.data.length > 0 && bosaiData.data.forEach((data) => {
    data.headline.forEach((headline) => execSync(`say -v Kyoko ${headline}`));
  });
});

ボタンを購入するボタンにする

ボタンを買えるボタンを作ります。

Seleniumを使います。
あなたとSelenium Server今すぐダウンロー

$ brew install chromedriver
$ npm install selenium-webdriver
amazon-dash-button-button.js
const DashButton = require('dash-button');
const {exec} = require('child_process');
const button = new DashButton("xx:xx:xx:xx:xx:xx");
const webdriver = require('selenium-webdriver');
const {By, until} = webdriver;

const driver = new webdriver.Builder().forBrowser('chrome').build();
// ウィルキンソン Dash Button
const targetURL = 'https://www.amazon.co.jp/Amazon-JK29LP-%E3%82%A6%E3%82%A3%E3%83%AB%E3%82%AD%E3%83%B3%E3%82%BD%E3%83%B3-Dash-Button/dp/B01L2WQ27O';
const amazonAccount = {
  mail :  'example@example.com',
  password :'password'
};
button.addListener(() => {
  driver.get('https://www.amazon.co.jp/');
  driver.findElement(By.css('#gw-sign-in-widget-sign-in-section a')).click();
  driver.findElement(By.css('[type="email"]')).sendKeys(amazonAccount.mail);
  driver.findElement(By.css('[type="password"]')).sendKeys(amazonAccount.password);
  driver.findElement(By.css('#signInSubmit')).click();
  driver.get(targetURL);
  driver.findElement(By.css('#add-to-cart-button')).click();
  driver.findElement(By.css('.hucSprite.s_checkout.hlb-checkout-button')).click();
  driver.findElement(By.css('[name="placeYourOrder1"]')).click();
  driver.quit();
});

デバッグに1000円使いました

頑張ってるあいつに砂を送りつけるボタンを作る

彼女ができてるエンジニアのリストをかたっぱしから精査してウィッシュリスト出してる奴がいたら送りつけたらいいと思います。責任は負いません。

手順は下を参考にしました。
Amazon ウィッシュリスト経由で砂 1 トンを送る方法

suna-do-zo.js
const DashButton = require('dash-button');
const {exec} = require('child_process');
const button = new DashButton("xx:xx:xx:xx:xx:xx");
const webdriver = require('selenium-webdriver');
const {By, until} = webdriver;

const driver = new webdriver.Builder().forBrowser('chrome').build();
// 洗い砂 20kg(12.5L)×30袋セット
const targetURL = 'https://www.amazon.co.jp/dp/B007VIBVO8';
const wishlistURL = 'https://www.amazon.co.jp/registry/wishlist/WHISHLISTID';
const amazonAccount = {
  mail :  'example@example.com',
  password :'eample.com'
};
button.addListener(() => {
  driver.get('https://www.amazon.co.jp/');
  driver.findElement(By.css('#gw-sign-in-widget-sign-in-section a')).click();
  driver.findElement(By.css('[type="email"]')).sendKeys(amazonAccount.mail);
  driver.findElement(By.css('[type="password"]')).sendKeys(amazonAccount.password);
  driver.findElement(By.css('#signInSubmit')).click();
  driver.get(wishlistURL);
  driver.findElement(By.css('[data-action="reg-item-inline-order"]')).click();

  driver.get(targetURL);
  driver.findElement(By.css('#add-to-cart-button')).click();
  driver.findElement(By.css('.hucSprite.s_checkout.hlb-checkout-button')).click();
  driver.findElement(By.css('#address-book-entry-1 [data-action="page-spinner-show"]')).click();

  driver.findElement(By.css('[name="placeYourOrder1"]')).click();
  driver.quit();
});

楽天で買う

さいごに

意外と電池の消耗が激しい。

30
22
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
30
22

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?