Created
October 31, 2016 07:20
-
-
Save sonkm3/c246b554b32ad6d327fab7c605c72724 to your computer and use it in GitHub Desktop.
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
# -*- coding: utf-8 -*- | |
import sys | |
from urllib.request import Request, urlopen | |
from urllib.parse import urlencode | |
# todo: logging | |
def send_notify(key, message, media_url=''): | |
url = 'https://notify-api.line.me/api/notify' | |
payload = {'message': message} | |
headers = {'Authorization': 'Bearer %s' % key} | |
if not media_url: | |
payload['imageThumbnail'] = media_url | |
payload['imageFullsize'] = media_url | |
sys.stderr.write('payload: '+ str(payload)) | |
sys.stderr.write('key: '+ str(key)) | |
request = Request(url = url, data = urlencode(payload).encode(encoding='ascii'), headers = headers) | |
response = urlopen(request) | |
sys.stderr.write('status: '+ str(response.status)) | |
return response.status |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment