Skip to content

Instantly share code, notes, and snippets.

@colspan
Created February 18, 2018 05:35
Show Gist options
  • Save colspan/d12fc7ce0644d0d2e0e376a95ba3b71f to your computer and use it in GitHub Desktop.
Save colspan/d12fc7ce0644d0d2e0e376a95ba3b71f to your computer and use it in GitHub Desktop.
gomify : gomi notifier with Google Home
const googlehome = require("google-home-notifier")
const dayDef = "日月火水木金土".split("")
function notify() {
const dt = new Date()
const weekCount = Math.ceil(dt.getDate() / 7)
let gomiText = ""
const noGomi = "今日はゴミを捨てる日ではありません。"
switch (dt.getDay()) {
case 0:
case 1:
gomiText = noGomi
break
case 2:
case 5:
gomiText = "今日は燃やすゴミの日です。"
break
case 3:
let gomiTypeWed = ""
switch (weekCount) {
case 1:
case 3:
gomiTypeWed = "プラスチックと燃やさないゴミ、プバツ、プバツ"
break
case 2:
case 4:
gomiTypeWed = "プラスチックとペットボトル、プペッ、プペッ"
break
case 5:
gomiTypeWed = "プラスチック、プッ、プッ"
break
}
gomiText = `今日は${gomiTypeWed}の日です。`
break
case 4:
if (weekCount % 2 == 0) {
gomiText = "今日は有害危険物のゴミの日です。"
} else {
gomiText = noGomi
}
break
case 6:
if (weekCount % 2 == 0) {
gomiText = "今日はリサイクルゴミの日です。紙、ダンボール、空き缶、空き瓶です。"
} else {
gomiText = noGomi
}
break
}
const text = `おはようございます。${dt.getMonth() + 1}月${dt.getDate()}日${dayDef[dt.getDay()]}曜日、${dt.getHours()}時${dt.getMinutes()}分です。${gomiText}`
console.log(text)
for (let ip of ["XXX.XXX.XXX.XXX"]) { // 配信したいGoogle HomeのIPアドレスリスト
googlehome.device("ダイニング ルーム", (lang = "ja"))
googlehome.ip(ip)
googlehome.accent("ja")
googlehome.notify(text, function(res) {
console.log(res)
})
}
}
let cron = require('node-cron')
cron.schedule('0,15,30,45 6 * * * *', notify)
cron.schedule('0,20,40 7 * * * *', notify)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment