end notification via line

以下の "line_notify.py"を使うと,次の2行をスクリプトの最後に貼るだけで,スクリプト終了のお知らせが,スクリプト名と現在ディレクトリ付きで,line経由で通知されます.

from xxxxx import line_notify

line_notify.end_notify()

# line_notify.py for python 2.7 & 3.6

import requests

def line(Me):

line_notify_token = 'Put your access token code'

line_notify_api = 'https://notify-api.line.me/api/notify'

message = '\n' + Me

payload = {'message': message}

headers = {'Authorization': 'Bearer ' + line_notify_token}

line_notify = requests.post(line_notify_api, data=payload, headers=headers)

def end_notify():

"""" return who (process name) and where (pwd)

This script will be used to send "end notification" of script. """

import os

import subprocess

cwd=os.getcwd()

pid=os.getpid()

str_command='ps u -p '+str(pid)

ret = subprocess.check_output(str_command,shell=True).decode('ascii')

ret=ret.split(' ')[-1]

str_message=ret + ' ends. \n\n'+cwd

line(str_message)

By using the following "line_notify.py", and simply just two lines at the end of your script, you get the end message with script name and current directory via line.

from xxxxx import line_notify

line_notify.end_notify()

# line_notify.py for python 2.7 & 3.6

import requests

def line(Me):

line_notify_token = 'Put your access token code'

line_notify_api = 'https://notify-api.line.me/api/notify'

message = '\n' + Me

payload = {'message': message}

headers = {'Authorization': 'Bearer ' + line_notify_token}

line_notify = requests.post(line_notify_api, data=payload, headers=headers)

def end_notify():

"""" return who (process name) and where (pwd)

This script will be used to send "end notification" of script. """

import os

import subprocess

cwd=os.getcwd()

pid=os.getpid()

str_command='ps u -p '+str(pid)

ret = subprocess.check_output(str_command,shell=True).decode('ascii')

ret=ret.split(' ')[-1]

str_message=ret + ' ends. \n\n'+cwd

line(str_message)