Пример #1
0
def __get_airframe_data(airframe_id):
    """ cached version of get_airframe_data()
    """
    airframe_xml = get_airframes_filename()
    if download_file_maybe(airframe_xml, get_airframes_url()):
        try:
            e = xml.etree.ElementTree.parse(airframe_xml).getroot()
            for airframe_group in e.findall('airframe_group'):
                for airframe in airframe_group.findall('airframe'):
                    if str(airframe_id) == airframe.get('id'):
                        ret = {'name': airframe.get('name')}
                        try:
                            ret['type'] = airframe.find('type').text
                        except:
                            pass
                        return ret
        except:
            pass
    return None
Пример #2
0
def download_airframes_maybe():
    """ download the airframes.xml if it does not exist or it's older than a day.
        returns True if the file can be used
    """
    airframes_file = get_airframes_filename()
    need_download = False
    if os.path.exists(airframes_file):
        elapsed_sec = time.time() - os.path.getmtime(airframes_file)
        if elapsed_sec / 3600 > 24:
            need_download = True
            os.unlink(airframes_file)
    else:
        need_download = True
    if need_download:
        print("Downloading airframes from " + get_airframes_url())
        try:
            urlretrieve(get_airframes_url(), airframes_file)
        except Exception as e:
            print("Download error: " + str(e))
            return False
    return True
Пример #3
0
def get_airframe_data(airframe_id):
    """ return a dict of aiframe data ('name' & 'type') from an autostart id.
    Downloads aiframes if necessary. Returns None on error
    """

    airframe_xml = get_airframes_filename()
    if download_file_maybe(airframe_xml, get_airframes_url()):
        try:
            e = xml.etree.ElementTree.parse(airframe_xml).getroot()
            for airframe_group in e.findall('airframe_group'):
                for airframe in airframe_group.findall('airframe'):
                    if str(airframe_id) == airframe.get('id'):
                        ret = {'name': airframe.get('name')}
                        try:
                            ret['type'] = airframe.find('type').text
                        except:
                            pass
                        return ret
        except:
            pass
    return None