Created
February 5, 2018 01:57
-
-
Save o8r/cbbbe5597b542450f281f3f192054c32 to your computer and use it in GitHub Desktop.
Simple utility to send a notify to LINE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env/python | |
| """ This sends a notification to LINE via LINE notify API. | |
| :param str token: API token | |
| :param *: messages | |
| """ | |
| import sys | |
| def main(): | |
| if len(sys.argv) < 2: # Token not provided | |
| usage(sys.argv) | |
| return 1 | |
| token = sys.argv[1] | |
| msg = ' '.join(sys.argv[2:]) | |
| line_notify(token, msg) | |
| def usage(argv): | |
| print("Usage: %s token messages..." % (argv[0]), file=sys.stderr) | |
| def line_notify(token, msg): | |
| import requests | |
| api = 'https://notify-api.line.me/api/notify' | |
| payload = {'message': msg} | |
| headers = {'Authorization': 'Bearer '+token} | |
| requests.post(api, data=payload, headers=headers) | |
| if __name__=='__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment