args = parser.parse_args()

if not args.db_conf:
    print("A valid URL db configuration file is needed!")
    exit(1)

if not args.airport:
    print("An Airport is needed!")
    exit(1)
else:
    if not args.start_time:
        args.start_time = datetime.date.today().strftime("%F") + " 00:00:00"
    dbconn = pr.connDB(args.db_conf)
    reporter = pr.readReporter(dbconn, args.reporter, printQuery=args.debug)
    airport = pr.readAirport(dbconn, args.airport, printQuery=args.debug)
    runways = pr.readRunways(dbconn, args.airport, printQuery=args.debug)
    for runway in runways:
        if args.debug:
            print(runway.to_JSON())
        if not args.runways or args.runways == runway.name:
            cur = pr.queryReportsDB(dbconn, myhex=args.hexcodes, myStartTime=args.start_time, \
                                    myEndTime=args.end_time,
                                    myflight=args.flights, maxAltitude=(
                                        int(args.committed_height) + airport.altitude),
                                    minAltitude=(airport.altitude - 150), myReporter=args.reporter,
                                    reporterLocation=reporter.location, printQuery=args.debug, \
                                    runways=runway.runway_area,
                                    postSql=" order by hex, report_epoch")
            data = pr.readReportsDB(cur, numRecs=10000)
            oldplane = None
Example #2
0
if args.debug:
    print(reporter.to_JSON())

postSql = None

if args.sortOrder:
    if args.sortOrder == "name":
        postSql = "order by name"
    elif args.sortOrder == "icao":
        postSql = "order by icao"
    elif args.sortOrder == "dist":
        postSql = "order by ST_Distance(location, '%s')" % reporter.location
    else:
        print("sort order requires one of dist, icao or name")
        exit(1)

airports = pr.readAirport(dbconn,
                          key='%',
                          maxDistance=(args.distance * 1000.0),
                          reporterLocation=reporter.location,
                          printQuery=args.debug,
                          postSql=postSql)

print(len(airports))
for airport in airports:
    print(airport.icao, airport.lat, airport.lon, airport.altitude,
          reporter.distance(airport) / 1000.0, airport.name)

#airport_list = pr.readAirport(dbconn, args.airport, printQuery=args.debug, maxDistance=args.distance, reporterLocation=reporter.)