def ping():
    weather = Weather('beijing')
    weatherInfoList = weather.getWeatherAllInfo()
    weatherinfo = ''
    for item in weatherInfoList:
        weatherinfo += item+'\n'
    response = make_response(weatherinfo)
    return response
def parseMsg():
    requestData = request.data
    map = MessageUtil.parseXml(requestData)
    fromUserName = map['FromUserName']
    toUserName = map['ToUserName']
    msgType = map['MsgType']
    content = map['Content'].encode('utf-8')

    #帮助信息
    if content == 'help':

        help_info = '养眼/色 : "美女"\n'
        help_info += 'ip查询 : "xxx.xxx.xxx.xxx"\n'
        help_info += '天气查询 : "天气:北京"\n'
        help_info += '景点查询 : "景点:xxx"\n'
        help_info += '机器人聊天'

        textMessage = RespTextMessage(fromUserName,toUserName,str(int(time.time())),'text','0',help_info)
        xmldata = MessageUtil.messageToTextXml(textMessage)

    #文章查看
    elif content == '文章':
        title = '这是标题'
        description = '这是描述这是描述这是描述这是描述这是描述这是描述'
        picUrl = url_for('static',filename='1.png',_external=True)
        url = 'http://blog.csdn.net/u010567606'
        article = Article(title,description,picUrl,url)
        articleList = [article]

        articleMessage = RespArticleMessage(fromUserName,toUserName,str(int(time.time())),'news','0',str(len(articleList)),articleList)
        xmldata = MessageUtil.messageToArticleXml(articleMessage)

    #养眼美女
    elif content == '美女':
        girl = Girl()
        articleList = girl.getGirlImage()

        articleMessage = RespArticleMessage(fromUserName,toUserName,str(int(time.time())),'news','0',str(len(articleList)),articleList)
        xmldata = MessageUtil.messageToArticleXml(articleMessage)

    #ip地址查询
    elif content.count('.')==3:
        ipLookup = IpLookup(content)
        l = ipLookup.getIpInfo()
        ipInfo = ''
        for item in l:
            ipInfo += item + '\n'

        textMessage = RespTextMessage(fromUserName,toUserName,str(int(time.time())),'text','0',ipInfo)
        xmldata = MessageUtil.messageToTextXml(textMessage)

    #景点查询
    elif content[0:content.find(':')] == '景点':
        attraction = Attraction(content[content.find(':')+1:])
        l = attraction.getAttractionInfo()
        attraction_info = ''
        for item in l:
            attraction_info += item + '\n\n'
        textMessage = RespTextMessage(fromUserName,toUserName,str(int(time.time())),'text','0',attraction_info)
        xmldata = MessageUtil.messageToTextXml(textMessage)

    #天气查询
    elif content[0:content.find(':')] == '天气':
        weather = Weather(content[content.find(':')+1:])
        weatherInfoList = weather.getWeatherAllInfo()
        weatherinfo = ''
        for item in weatherInfoList:
            weatherinfo += item+'\n'

        textMessage = RespTextMessage(fromUserName,toUserName,str(int(time.time())),'text','0',weatherinfo)
        xmldata = MessageUtil.messageToTextXml(textMessage)

    else:
        robot = Robot(content)
        msg = robot.chat()

        textMessage = RespTextMessage(fromUserName,toUserName,str(int(time.time())),'text','0',msg)
        xmldata = MessageUtil.messageToTextXml(textMessage)

    response = make_response(xmldata)
    response.content_type = 'application/xml'
    return response