LoginSignup
243
221

More than 3 years have passed since last update.

今日は何のゴミ出しの日かをLineに通知してくれるプログラムを作ってみた

Last updated at Posted at 2019-06-11

朝ゴミを出すのを忘れちゃう、今日が何のゴミの日かを忘れちゃう一人暮らし初心者(私みたいな)用に、朝Lineに今日は何のゴミを出せば良いのかを通知してくれるプログラムを実装してみました。

以下のプログラムをcronを用いて通知してほしい時間に定期実行することで、Lineに通知が届き、ゴミ出しを忘れることを防止できるはず、、、です。

garbage_notify.py
import datetime
import requests

weekday = datetime.date.today().weekday()

def send(message):
  url = "https://notify-api.line.me/api/notify"
  access_token = 'Your Access Token'#自身のアクセストークン(ページ下の記事参照)
  headers = {'Authorization': 'Bearer ' + access_token}
  payload = {'message': message}
  requests.post(url, headers = headers, params = payload)

def garbage_day():
  if weekday == 0 or weekday == 4:#0:月曜、4:金曜
    send('今日は燃えるゴミの日')
  elif weekday == 1:#1:火曜
    send('今日はプラスチックの日')
  elif weekday == 3:#3:木曜
    send('今日は紙の日')
  elif weekday == 5:#5:土曜
    send('今日は缶・ビン・ペットボトルの日')
  else:pass

if __name__ == "__main__":
  garbage_day()

cronの書き方は以下の記事を参考にしてください。
https://qiita.com/tossh/items/e135bd063a50087c3d6a

Line notifyの書き方は以下の記事を参考にしました。アクセストークンの取得方法を参考にしてください。
https://qiita.com/moriita/items/5b199ac6b14ceaa4f7c9

Qiita初心者なので、書き方がおかしい点、間違っている点等あればご指摘いただけると幸いです。

243
221
12

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
243
221