LoginSignup
4
10

More than 5 years have passed since last update.

PythonのプログラムからLINE通知する方法

Last updated at Posted at 2018-11-11

PythonのプログラムからLINE通知する方法。

botの監視用としても使えるし、バックテスト用としても使える。
買い時が来たら知らせてくれるようにする事でチャートに張り付いていなくても大丈夫になるかもしれない便利機能。

LINE公式サイトからトークンを発行

プログラムにLINE通知機能を組み込む

requests をインポート

import requests

def文を使って関数 lineNotify を定義

def lineNotify(message):
    line_notify_token = "ここに取得したトークンを入力"
    line_notify_api = "https://notify-api.line.me/api/notify"

    payload = {'message':message}
    headers = {'Authorization': 'Bearer' + line_notify_token}
    requests.post(line_notify_api, data=payload, headers=headers}

変数 message に出力したい文章を入れる

message = "LINEで通知させたい文言"

関数 lineNotify を呼び出す

lineNotify(message)

または、関数 lineNotify を呼び出す時に引数を渡す

lineNotify("LINEで通知させたい文言")
4
10
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
4
10