Beispiel #1
0
def index():
    signature = request.args.get("signature")
    timestamp = request.args.get("timestamp")
    nonce = request.args.get("nonce")
    echostr = request.args.get("echostr")

    if request.method == "GET":
        print(echostr)
        return echostr

    elif request.method == "POST":
        body_text = request.data

        xml_store = XMLStore(body_text)
        recv_data = xml_store.xml2dict

        if False:
            print("<<<<<<<<<< recv <<<<<<<<<<<<<<")
            print(recv_data)
            print("<<<<<<<<<< recv <<<<<<<<<<<<<<")

        target = recv_data.get("FromUserName", "")

        if recv_data.get("MsgType") == "image":
            msg = {"target": target, "source": SOURCE_ID}

            pic_url = recv_data.get("PicUrl", "")
            oxf = Oxford(pic_url)
            ages = oxf.get_ages()
            content = ages
            tr = TextReply(message=msg, content=content)
            rs = tr.render()


        else:
            msg = {"target": target, "source": SOURCE_ID}
            content = "Sorry, your input is not suported."
            tr = TextReply(message=msg, content=content)
            rs = tr.render()

        if DEBUG:
            print(">>>>>>>>>>> send >>>>>>>>>>>>>")
            print(rs)
            print(">>>>>>>>>>> send >>>>>>>>>>>>>")

        return make_response(rs)
Beispiel #2
0
    def test_XMLStore_xml2dict(self):
        msg = {"target": "A", "source": "b"}
        content = "text......."
        tr = TextReply(message=msg, content=content)
        rs = tr.render()

        xmls = XMLStore(rs)
        d = xmls.xml2dict
        print(d)
Beispiel #3
0
 def test_TextReply_render(self):
     msg = {"target": "A", "source": "b"}
     content = "text......."
     tr = TextReply(message=msg, content=content)
     rs = tr.render()
     print(rs)