Help us understand the problem. What is going on with this article?

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

More than 3 years have passed since last update.

なにも考えずにいろいろします
この記事の前に、環境設定の参考として下記事に目を通すことをオススメします
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();
});

楽天で買う

さいごに

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

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした