send2IFTTT.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:ifttt-line 作者: MypaceEngine 项目源码 文件源码
def sendData(ifttt_event, ifttt_key, senderID, from_id, event_type, msg_data):
    if ifttt_key == None:
        send2Line.sendText(str(senderID), const.MSG_NONREGISTRATION)
        return
    if msg_data.count('\n'):
        msg_data = u"<pre>" + msg_data + u"</pre>"
    form_fields = {
        "value1": from_id,
        "value2": event_type,
        "value3": msg_data,
    }
    logging.debug(form_fields)
    logging.debug(ifttt_key)
    requestStr = json.dumps(form_fields, ensure_ascii=False)
    # requestStr=requestStr.replace('\n', '\\n').replace('\r', '')
    url = "https://maker.ifttt.com/trigger/" + ifttt_event + "/with/key/" + ifttt_key
    result = urlfetch.fetch(
        url=url,
        payload=requestStr,
        method=urlfetch.POST,
        headers={
            'Content-Type': ' application/json'
        }
    )
    logging.debug(result.status_code)
    if result.status_code == 200:
        logging.debug(result.content)
    elif result.status_code == 401:
        send2Line.sendText(str(senderID), const.MSG_MAKERKEY_FAILED)
        logging.debug(result.content)
    else:
        logging.debug(result.content)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号