コード例 #1
0
def saveData(data):
    if len(data) == 0:
        return

    db = MySQLdb.connect(
        host="systemintegration.cmavq3o8re9w.us-east-1.rds.amazonaws.com",
        user="******",
        passwd="datenbank",
        db="flugdaten",
    )
    cursor = db.cursor()
    cnt = 0

    for brbPlane in data:
        flightId = brbPlane[jsonReader.flightId()]
        startAirport = brbPlane[jsonReader.startAirport()]
        targetAirport = brbPlane[jsonReader.targetAirport()]
        timestamp = int(time.time())
        replaceQuery = "REPLACE INTO {0} SET id='{4}',startairport='{2}',targetairport='{3}',reg_date=FROM_UNIXTIME({1})".format(
            SQL_TABLENAME, timestamp, startAirport, targetAirport, flightId
        )
        cursor.execute(replaceQuery)
        if int(cursor.rowcount) != -1:
            cnt += 1

    print "{0} aircrafts above Brandenburg saved in DB.".format(cnt)
    db.commit()
    db.close()
コード例 #2
0
def filterData(aircraftData):
    filteredAircrafts = []  # instanciate Resultlist
    for aircraft in aircraftData:
        flightId = aircraft[jsonReader.flightId()]
        startAirport = aircraft[jsonReader.startAirport()]
        targetAirport = aircraft[jsonReader.targetAirport()]
        if flightId != "" and startAirport != "" and targetAirport != "":
            filteredAircrafts.append(aircraft)
    print colored(
        "{0} aircrafts found. ({1} omitted -> no data)".format(
            len(aircraftData), len(aircraftData) - len(filteredAircrafts)
        ),
        "green",
    )  # (len(aircraftData)==1500) if 'green' else 'red')
    return filteredAircrafts