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.
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
--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
--Imported from another file and made available --You can now send Line messages to yourself using LineNotify
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,)
Click your name in the upper right to go to My Page.
Click Issue Token at the bottom of My Page.
Select the group you want to send and copy the issued token
Set access token after cloning
self.access_token = 'Put the obtained token here'
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.
--I tried sending LineNotify using python --Code modularization
If anyone can use it, please try it.
Recommended Posts