示例#1
0
def create_participant_from_name(name):
    """get pilot info from pilot name database and create Participant obj
        It's almost sure that we get more than one result.
        This function gives back a Participant ONLY if we get a single result.
        get_pilots_from_name gives a list of Dict"""
    from pilot.participant import Participant

    body = f"""<?xml version="1.0" encoding="utf-8"?>
                <soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
                  <soap12:Body>
                    <FindPilot xmlns="http://civlrankings.fai.org/">
                      <name>{name}</name>
                    </FindPilot>
                  </soap12:Body>
                </soap12:Envelope>"""
    response = requests.post(url, data=body, headers=headers)
    # print(response.content)
    root = ET.fromstring(response.content)
    data = root.find('.//{http://civlrankings.fai.org/}FindPilotResponse')
    if not len(data.findall(
            '{http://civlrankings.fai.org/}FindPilotResult/')) == 1:
        '''we don't have a single result'''
        return None

    result = data.findall('{http://civlrankings.fai.org/}FindPilotResult//')
    pilot = Participant()
    pilot.name = result[1].text
    pilot.nat = result[2].text
    pilot.civl_id = int(result[6].text)
    pilot.sex = 'F' if result[7].text == 'true' else 'M'
    pilot.team = result[8].text
    pilot.glider = result[9].text
    return pilot
示例#2
0
def create_participant_from_CIVLID(civl_id):
    """get pilot info from CIVL database and create Participant obj"""
    from pilot.participant import Participant

    body = f"""<?xml version='1.0' encoding='utf-8'?>
                <soap12:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap12='http://www.w3.org/2003/05/soap-envelope'>
                    <soap12:Body>
                        <GetPilot xmlns='http://civlrankings.fai.org/'>
                            <CIVLID>{civl_id}</CIVLID>
                        </GetPilot>
                    </soap12:Body>
                </soap12:Envelope>"""
    response = requests.post(url, data=body, headers=headers)
    # print(response.content)
    root = ET.fromstring(response.content)
    data = root.find('.//{http://civlrankings.fai.org/}GetPilotResponse')
    if not data or not data.find(
            '{http://civlrankings.fai.org/}GetPilotResult'):
        '''we don't have a result'''
        return None
    result = data.findall('{http://civlrankings.fai.org/}GetPilotResult//')
    pilot = Participant(civl_id=civl_id)
    pilot.name = result[0].text
    pilot.nat = result[1].text
    pilot.sex = 'F' if result[6].text == 'true' else 'M'
    pilot.team = result[7].text
    pilot.glider = result[8].text
    return pilot