I tried Line notification in Python

I made a program to send LineNotify using python, so I will post it. I hope it will be helpful for those who want to make notifications from now on.

table of contents

If you don't have to read the code, you can start from 4. 1. Background [2. What I did](#What I did) [3. Code](# code) [4. How to use](# How to use) 5. Summary

background </ span>

--The learning time of machine learning is very long ... ――I want to do other things while learning ――I want you to tell me when you finish learning

What I did </ span>

--Imported from another file and made available --You can now send Line messages to yourself using LineNotify

code </ span>

I could have made it simpler, but I made it modular so that I could continue to use it. The code is on Github . If you do not have requests installed, you cannot use it, so please install it.

>> pip install requests

Actual code ↓ (Since only simple processing is written, explanation is omitted.)

line_notify.py


"""
class module
Define a class that uses LINE Notify
"""
# coding: utf-8
import requests


class LineNotify():
    """
Class for LINE notification
    """

    def __init__(self):
        """
        Parameters
        ----------
        url: string
Line Notify destination
        access_token: string
LineNotify access token
        """
        self.url = "https://notify-api.line.me/api/notify"
        self.access_token = 'F78NKUuw6BhAytCPpjw2QgXXMmxV58iOxBA0HtQfYzh'

    def post_linenotify(self, message):
        """
Send a message to Line

        Parameters
        ----------
        self : self
Class itself
        message: string
The message actually sent
        """
        headers = {'Authorization': 'Bearer ' + self.access_token}
        payload = {'message': message}
        requests.post(self.url, headers=headers, params=payload,)

How to use </ span>

Get an access token from LineNotify official .

Click your name in the upper right to go to My Page. スクリーンショット 2020-06-24 22.30.28.png

Click Issue Token at the bottom of My Page. スクリーンショット 2020-06-24 22.31.18.png

Select the group you want to send and copy the issued token スクリーンショット 2020-06-24 22.32.01.png

Clone from Github

Set access token after cloning

self.access_token = 'Put the obtained token here'

Write the code that actually sends the message

main.py


from line_notify import LineNotify


def main:
    notify = LineNotify()
    message = 'Message to send'
    notify.post_linenotify(message)


if __name__ == '__main__':
    main()

I think you can use it like this.

Summary </ span>

--I tried sending LineNotify using python --Code modularization

If anyone can use it, please try it. 

Recommended Posts

I tried Line notification in Python
I tried to implement PLSA in Python
I tried to implement permutation in Python
I tried to implement PLSA in Python 2
I tried using Bayesian Optimization in Python
I tried to implement ADALINE in Python
I tried to implement PPO in Python
I tried Python> autopep8
I tried Python> decorator
I tried simulating the "birthday paradox" in Python
I tried the least squares method in Python
[Memo] I tried a pivot table in Python
I tried non-blocking I / O Eventlet behavior in Python
I tried adding a Python3 module in C
I tried to implement selection sort in python
I tried fp-growth with python
I tried scraping with Python
I wrote python in Japanese
Fizzbuzz in Python (in one line)
Try LINE Notify in Python
I tried Python C extension
[Python] I tried using OpenPose
I tried gRPC with Python
I tried scraping with python
I understand Python in Japanese!
What I learned in Python
I tried to graph the packages installed in Python
I tried using TradeWave (BitCoin system trading in Python)
I tried to implement a pseudo pachislot in Python
I tried to implement Dragon Quest poker in Python
I tried to implement GA (genetic algorithm) in Python
I tried to summarize how to use pandas in python
Make python segfault in one line
I tried to create API list.csv in Python from swagger.yaml
I tried to touch Python (installation)
I tried "a program that removes duplicate statements in Python"
I wrote Fizz Buzz in Python
I tried "How to get a method decorated in Python"
I tried programming the chi-square test in Python and Java.
I tried running GAN in Colaboratory
I tried using Thonny (Python / IDE)
I tried Grumpy (Go running Python).
I learned about processes in Python
I can't install scikit-learn in Python
I created a class in Python and tried duck typing
I tried to implement the mail sending function in Python
I wrote the queue in Python
I tried to make a stopwatch using tkinter in python
web coder tried excel in Python
I tried running prolog with python 3.8.2.
[Introduction] Insert line breaks in Python 3
I tried SMTP communication with Python
I tried to implement blackjack of card game in Python
Implemented in 1 minute! LINE Notify in Python
[Python] I tried using YOLO v3
I wrote the stack in Python
Movement that changes direction in the coordinate system I tried Python 3
I tried to implement a misunderstood prisoner's dilemma game in Python
I tried to make a 2channel post notification application with Python
I put Python 2.7 in Sakura VPS 1GB.
I tried to summarize Python exception handling