Esempio n. 1
0
    def run(self, commit, welt2000_path):
        welt2000 = get_database(path=welt2000_path)

        self.current_date = datetime.utcnow()
        i = 0

        for airport_w2k in welt2000:
            if (airport_w2k.type != 'airport'
                    and airport_w2k.type != 'glider_site'
                    and airport_w2k.type != 'ulm'):
                continue

            i += 1
            if i % 100 == 0:
                db.session.flush()
                print str(
                    i
                ) + ": " + airport_w2k.country_code + " " + airport_w2k.name

            # try to find this airport in the database
            near_airport = Airport.query() \
                .filter(and_(Airport.short_name == airport_w2k.short_name,
                             Airport.country_code == airport_w2k.country_code)) \
                .filter(or_(Airport.valid_until == None, Airport.valid_until > self.current_date)) \
                .first()

            # fall back to location-search if airport is not found
            # and only reuse this airport if it's within 250 meters of the old one...
            if near_airport is None or near_airport.distance(
                    airport_w2k) > 250:
                near_airport = Airport.by_location(airport_w2k,
                                                   distance_threshold=0.0025)

            if near_airport is None:
                # this airport is not in our database yet. add it...
                self.add_airport(airport_w2k)

            else:
                # seems to be the same airport. update with current values
                self.show_differences(near_airport, airport_w2k)
                self.update_airport(near_airport, airport_w2k)

        db.session.flush()

        # now invalidate all remaining airports

        invalid_airports = Airport.query() \
            .filter(Airport.time_modified < self.current_date) \
            .filter(or_(Airport.valid_until == None, Airport.valid_until > self.current_date))

        for airport in invalid_airports:
            print "{}  {}  {}" \
                .format(airport.country_code, airport.name, airport.icao)
            print "  invalidated"

            airport.valid_until = self.current_date

        if commit:
            db.session.commit()
Esempio n. 2
0
    def run(self, commit, welt2000_path):
        welt2000 = get_database(path=welt2000_path)

        self.current_date = datetime.utcnow()
        i = 0

        for airport_w2k in welt2000:
            if (airport_w2k.type != 'airport' and
                    airport_w2k.type != 'glider_site' and
                    airport_w2k.type != 'ulm'):
                continue

            i += 1
            if i % 100 == 0:
                db.session.flush()
                print str(i) + ": " + airport_w2k.country_code + " " + airport_w2k.name

            # try to find this airport in the database
            near_airport = Airport.query() \
                .filter(and_(Airport.short_name == airport_w2k.short_name,
                             Airport.country_code == airport_w2k.country_code)) \
                .filter(or_(Airport.valid_until == None, Airport.valid_until > self.current_date)) \
                .first()

            # fall back to location-search if airport is not found
            # and only reuse this airport if it's within 250 meters of the old one...
            if near_airport is None or near_airport.distance(airport_w2k) > 250:
                near_airport = Airport.by_location(airport_w2k, distance_threshold=0.0025)

            if near_airport is None:
                # this airport is not in our database yet. add it...
                self.add_airport(airport_w2k)

            else:
                # seems to be the same airport. update with current values
                self.show_differences(near_airport, airport_w2k)
                self.update_airport(near_airport, airport_w2k)

        db.session.flush()

        # now invalidate all remaining airports

        invalid_airports = Airport.query() \
            .filter(Airport.time_modified < self.current_date) \
            .filter(or_(Airport.valid_until == None, Airport.valid_until > self.current_date))

        for airport in invalid_airports:
            print "{}  {}  {}" \
                .format(airport.country_code, airport.name, airport.icao)
            print "  invalidated"

            airport.valid_until = self.current_date

        if commit:
            db.session.commit()
Esempio n. 3
0
                    nargs='?',
                    metavar='WELT2000.TXT',
                    help='path to the WELT2000 file')

args = parser.parse_args()

if not to_envvar(args.config):
    parser.error('Config file "{}" not found.'.format(args.config))

from skylines import db, app
from skylines.model import Airport
from skylines.lib.waypoints.welt2000 import get_database

app.test_request_context().push()

welt2000 = get_database(path=args.welt2000_path)

i = 0

for airport_w2k in welt2000:
    if (airport_w2k.type != 'airport' and airport_w2k.type != 'glider_site'
            and airport_w2k.type != 'ulm'):
        continue

    i += 1
    if i % 100 == 0:
        db.session.flush()
        print str(i) + ": " + airport_w2k.country_code + " " + airport_w2k.name

    airport = Airport()
    airport.location = airport_w2k
Esempio n. 4
0
    if changed or distance > 0.1:
        print "{}  {}  {}" \
            .format(airport.country_code, airport.name, airport.icao)

        if distance > 0.1:
            print "  moved by {}m".format(distance)

        for item in changed:
            print "  {} from {} to {}" \
                .format(item, row2dict(airport)[item], airport_w2k.__dict__[item])


app.test_request_context().push()

welt2000 = get_database(path=args.welt2000_path)

current_date = datetime.utcnow()
i = 0

for airport_w2k in welt2000:
    if (airport_w2k.type != 'airport' and
            airport_w2k.type != 'glider_site' and
            airport_w2k.type != 'ulm'):
        continue

    i += 1
    if i % 100 == 0:
        db.session.flush()
        print str(i) + ": " + airport_w2k.country_code + " " + airport_w2k.name
Esempio n. 5
0
sys.path.append(os.path.dirname(sys.argv[0]))

conf_path = '/etc/skylines/production.ini'
if len(sys.argv) > 1:
    conf_path = sys.argv[1]
    del sys.argv[1]

if len(sys.argv) != 1:
    print >>sys.stderr, "Usage: %s [config.ini]" % sys.argv[0]
    sys.exit(1)

conf = appconfig('config:' + os.path.abspath(conf_path))
load_environment(conf.global_conf, conf.local_conf)

welt2000 = get_database()

i = 0

for airport_w2k in welt2000:
    if airport_w2k.type != 'airport' \
        and airport_w2k.type != 'glider_site' \
        and airport_w2k.type != 'uml':
      continue

    i += 1
    if i%100 == 0:
        DBSession.flush()
        print str(i) + ": " + airport_w2k.country_code + " " + airport_w2k.name

    airport = Airport()
Esempio n. 6
0
    conf_path = sys.argv[1]
    del sys.argv[1]

welt2000_path = None
if len(sys.argv) > 1:
    welt2000_path = sys.argv[1]
    del sys.argv[1]

if len(sys.argv) != 1:
    print >>sys.stderr, "Usage: %s [config.ini] [WELT2000.TXT]" % sys.argv[0]
    sys.exit(1)

conf = appconfig('config:' + os.path.abspath(conf_path))
load_environment(conf.global_conf, conf.local_conf)

welt2000 = get_database(path=welt2000_path)

i = 0

for airport_w2k in welt2000:
    if (airport_w2k.type != 'airport' and
            airport_w2k.type != 'glider_site' and
            airport_w2k.type != 'ulm'):
        continue

    i += 1
    if i % 100 == 0:
        DBSession.flush()
        print str(i) + ": " + airport_w2k.country_code + " " + airport_w2k.name

    airport = Airport()