일단 LINE에 알림을 원하기 때문에 적절한 스크립트를 만들었습니다.

4251 단어 파이썬LineNotify

동기


  • 사내 GPU 서버에서 AI를 학습할 때 학습이 완료되기까지 매우 시간이 걸립니다.
  • 눈치채면 끝나고, 같은 것이 많다
  • 급한 학습의 경우 등은 곧 후속 작업에 우울하고 싶다



  • 그래서 학습이 끝나면 어떠한 형태로 통지를 갖고 싶다고 생각했습니다.

    그래서, LINE에 통지가 오면 뭐 어디에 있어도 수신할 수 있을 것 같기 때문에,
    쉽게 LINE에서 알림이 오는 스크립트를 Python으로 만들었습니다.

    코드


  • 전제

  • LINE Notify 페이지 내 페이지에서 액세스 토큰이 발행되었습니다


  • 일단 만들어 졌기 때문에 매우 적합합니다
    Python2.7 환경에서 작동 확인했습니다.

    line_notification.py
    import subprocess
    import argparse
    
    if __name__ == '__main__':
        parser = argparse.ArgumentParser(
            prog='line_notification.py',
            usage='Exec on terminal.',
            add_help=True,
        )
        parser.add_argument('-t', '--token', help='LINE ACCESS TOKEN', required=True, type=str)
        parser.add_argument('-m', '--message', help='message data', required=True, type=str)
        args = parser.parse_args()
    
        # LINE notification
        command = 'curl -X POST -H \'Authorization: Bearer {TOKEN}\' -F \"message={MESSAGE}\" https://notify-api.line.me/api/notify'.format(
            TOKEN=args.token,
            MESSAGE=args.message
        )
        subprocess.call(command, shell=True)
    

    사용법


    python line_notification.py -t "ACCESS_TOKEN" -m "MESSAGE"
    

    좋은 웹페이지 즐겨찾기