Example #1
0
class QueueModel(QAbstractTableModel):

    # Roles definitions
    #
    QueueTypeRole = Qt.UserRole + 1
    LiveRole = Qt.UserRole + 2
    FlightIATARole = Qt.UserRole + 3
    FlightICAORole = Qt.UserRole + 4
    ICAODEPRole = Qt.UserRole + 5
    ACFTRole = Qt.UserRole + 6
    ETARole = Qt.UserRole + 7
    ETAUTCRole = Qt.UserRole + 8
    ETAUTCHourRole = Qt.UserRole + 9
    GroundSpeedRole = Qt.UserRole + 10

    _roleNames = {
        QueueTypeRole: b"queue_type",
        LiveRole: b"live",
        FlightIATARole: b"flight_iata",
        FlightICAORole: b"flight_icao",
        ICAODEPRole: b"icao_dep",
        ACFTRole: b"acft",
        ETARole: b"eta",
        ETAUTCRole: b"eta_utc",
        ETAUTCHourRole: b"eta_utc_hour",
        GroundSpeedRole: b"ground_speed"
    }

    def __init__(self, codeIATA, parent=None):
        super(QueueModel, self).__init__(parent)

        self._QUEUE = []
        self._codeIATA = codeIATA

        self._fapi = FlightData()
        try:
            self._fapi.login('*****@*****.**', 'monrepo1')
            print('Logged in seccesfully...')
            self.update()
            print('Updated')
        except:
            print('Logged in failed.')
            sys.exit(0)

    def roleNames(self):
        return self._roleNames

    def flags(self, index):
        return Qt.ItemIsEditable | Qt.ItemIsEnabled

    def columnCount(self, parent=QModelIndex()):
        return len(self._roleNames)

    def rowCount(self, parent=QModelIndex()):
        return len(self._QUEUE)

    def data(self, index, role=Qt.DisplayRole):
        if not index.isValid():
            return QVariant()

        row = index.row()
        col = role - Qt.UserRole - 1
        return self._QUEUE[row][col]

    def update(self):
        self.beginResetModel()

        self._QUEUE = []

        self.updateARR()
        print('(' + self._codeIATA + ') Arrival Queue updated succesfully.')
        print(self._QUEUE)

        #        self.updateDEP()
        #        print('(' + self._codeIATA + ') Departure Queue updated seccesfully.')

        self._QUEUE.sort(key=lambda row: row[7])

        self.endResetModel()

    def updateARR(self):
        arrs = self._fapi.get_airport_arrivals(self._codeIATA)
        arrs = json.loads(json.dumps(arrs))
        arrs = sorted(arrs,
                      key=lambda k: k['flight']['time']['other']['eta'],
                      reverse=True)
        arrs = arrs[::-1]

        for arr in arrs:
            live = arr['flight']['status']['live']

            if bool(live) is False:
                pass
            else:
                queue_type = 'ARR'

                flight_iata = arr['flight']['identification']['number'][
                    'default']  # IATA flight code
                flight_icao = arr['flight']['identification'][
                    'callsign']  # ICAO flight code

                dep_icao = arr['flight']['airport']['origin']['code'][
                    'icao']  # ICAO departure airport code

                if arr['flight']['aircraft'] == 'None':
                    acft = 'None'
                else:
                    acft = arr['flight']['aircraft']['model'][
                        'code']  # ACFT code

                eta = arr['flight']['status']['text']  # ETA local time
                eta_utc = arr['flight']['time']['estimated'][
                    'arrival']  # ETA UTC
                if eta_utc == 'None':
                    eta_utc = '0'

                if arr['flight']['airline'] == 'None':
                    airline_icao = 'None'
                else:
                    airline_icao = arr['flight']['airline']['code']['icao']

                if (eta.find('Estimated') != -1):
                    #                    ground_speed = acft_details.get_ground_speed(flight_icao, airline_icao)
                    ground_speed = 0

                    arr = [
                        queue_type, live, flight_iata, flight_icao, dep_icao,
                        acft,
                        str(eta),
                        int(eta_utc),
                        datetime.datetime.utcfromtimestamp(int(eta_utc)).hour,
                        ground_speed
                    ]

                    self.beginInsertRows(QModelIndex(), self.rowCount(),
                                         self.rowCount())
                    self._QUEUE.append(arr)
                    self.endInsertRows()

    def updateDEP(self):
        deps = self._fapi.get_airport_departures(self._codeIATA)
        deps = json.loads(json.dumps(deps))
        deps = sorted(deps,
                      key=lambda k: k['flight']['time']['other']['eta'],
                      reverse=True)
        deps = deps[::-1]

        for dep in deps:
            queue_type = 'DEP'
            live = dep['flight']['status']['live']
            if bool(live) is True:
                flight_iata = dep['flight']['identification']['number'][
                    'default']  # IATA flight code
                flight_icao = dep['flight']['identification'][
                    'callsign']  # ICAO flight code
                #                dep_icao = dep['flight']['airport']['origin']['code']['icao'] # ICAO departure airport code
                dep_icao = None

            if dep['flight']['aircraft'] == 'None':
                acft = 'None'
            else:
                acft = dep['flight']['aircraft']['model']['code']  # ACFT code

            eta = dep['flight']['status']['text']  # ETA local time
            eta_utc = dep['flight']['time']['estimated'][
                'departure']  # ETA UTC
            if eta_utc == 'None':
                eta_utc = '0'

            if dep['flight']['airline'] == 'None':
                airline_icao = 'None'
            else:
                airline_icao = dep['flight']['airline']['code']['icao']

            if (eta.find('Estimated') != -1):
                ground_speed = 0
                dep = [
                    queue_type, live, flight_iata, flight_icao, dep_icao, acft,
                    str(eta),
                    int(eta_utc),
                    datetime.datetime.utcfromtimestamp(int(eta_utc)).hour,
                    ground_speed
                ]

                self.beginInsertRows(QModelIndex(), self.rowCount(),
                                     self.rowCount())
                self._QUEUE.append(dep)
                self.endInsertRows()
Example #2
0
def flights():
    while True:
        f = FlightData()
        airport = "DUB"
        arrival_list = f.get_airport_arrivals(airport, 1, 10)
        departures_list = f.get_airport_departures(airport, 1, 38)

        doc = open("template.html")
        soup = bs(doc)

        #iterate through current arriving flights and save data to dict
        #and place in correct location in table
        x = 1
        for flights in arrival_list:
            arrival_dict = {}

            #save flight data to dict
            arrival_dict["flightNumber"] = flights["flight"]["identification"]["number"]["default"]
            airline = flights["flight"]["airline"]["name"]
            if len(airline) > 23:
                temp = airline[0:22]
                airline = "{0:<22}".format(temp)
            arrival_dict["airline"] = airline
            arrival_dict["terminal"] = flights["flight"]["airport"]["destination"]["info"]["terminal"]

            estArrivalTime = flights["flight"]["time"]["estimated"]["arrival"]
            if estArrivalTime != 'None':
                utc_time = datetime.fromtimestamp(int(estArrivalTime), timezone.utc)
                local_time = utc_time.astimezone()
                estArrivalTime = (local_time.strftime("%H:%M"))
            arrival_dict["estArrivalTime"] = estArrivalTime

            arrivalTime = flights["flight"]["time"]["scheduled"]["arrival"]
            utc_time = datetime.fromtimestamp(int(arrivalTime), timezone.utc)
            local_time = utc_time.astimezone()
            arrivalTime = (local_time.strftime("%H:%M"))
            arrival_dict["arrivalTime"] = arrivalTime

            origin = flights["flight"]["airport"]["origin"]["name"]
            if len(origin) > 35:
                temp = origin[0:34]
                origin = "{0:<34}".format(temp)
            arrival_dict["origin"] = origin

            #place flight data into table
            for tele in soup.find_all("td"):
                telep = tele.find_parent("tr")
                table = tele.find_parent("table")
                if table["id"] == "arrivals":
                    if telep["id"] == str(x):
                        tele.string = arrival_dict[tele["id"]]
            x += 1

        #iterate through current departing flights and save data to dict
        #and place in correct location in table
        x = 1
        for flights in departures_list:
            departure_dict = {}

            #save flight data to dict
            departure_dict["flightNumber"] = flights["flight"]["identification"]["number"]["default"]
            airline= flights["flight"]["airline"]["name"]
            if len(airline) > 23:
                temp = airline[0:22]
                airline = "{0:<22}".format(temp)
            departure_dict["airline"] = airline
            departure_dict["terminal"] = flights["flight"]["airport"]["origin"]["info"]["terminal"]

            estDepartureTime = flights["flight"]["time"]["estimated"]["departure"]
            if estDepartureTime != 'None':
                utc_time = datetime.fromtimestamp(int(estDepartureTime), timezone.utc)
                local_time = utc_time.astimezone()
                estDepartureTime = (local_time.strftime("%H:%M"))
            departure_dict["estDepartureTime"] = estDepartureTime

            departureTime = flights["flight"]["time"]["scheduled"]["departure"]
            utc_time = datetime.fromtimestamp(int(departureTime), timezone.utc)
            local_time = utc_time.astimezone()
            departureTime = (local_time.strftime("%H:%M"))
            departure_dict["departureTime"] = departureTime

            destination = flights["flight"]["airport"]["destination"]["name"]
            if len(destination) > 35:
                temp = destination[0:34]
                destination = "{0:<34}".format(temp)
            departure_dict["destination"] = destination

            #place flight data into table
            for tele in soup.find_all("td"):
                telep = tele.find_parent("tr")
                table = tele.find_parent("table")
                if table["id"] == "departures":
                    if telep["id"] == str(x):
                        tele.string = departure_dict[tele["id"]]
            x += 1

        #write changes to html file
        doc.close()
        html = soup.prettify("utf-8")
        with open("index.html", "wb") as file:
            file.write(html)

        time.sleep(180)
Example #3
0
    api=FlightData(apiuser,apipass)
    api.login(apiuser,apipass)
    # Don't forget to: api.logout()
else :
    api=FlightData()    # Skip API credentials


if query == 1 : 
    if nmax == 0:
        alist = api.get_airport_arrivals(airport);    # Return: a JSON dictionary of xxxxx 
    else :
        alist = api.get_airport_arrivals(airport, page=1, limit=nmax); 
    if not alist : iataerr();
elif query == 2 : 
    if nmax == 0 :
        alist = api.get_airport_departures(airport);  # Return: a JSON dictionary of xxxxx
    else :
        alist = api.get_airport_departures(airport, page=1, limit=nmax);
    if not alist : iataerr();
elif query == 3 : 
    try: 
        alist = api.get_airports(country);            # Return: a list of (name,code) tuples. # api.get_airports('India')[10:15]
    except AttributeError :
        airerr();
    if not alist : airerr();
elif query == 4 : 
    try: 
        alist = api.get_airport_details(airport);     # Return: 
        blist = api.get_airport_weather(airport);     # Return: 
    except AttributeError :
        iataerr();
Example #4
0
def realtime_airport_departures(iata):
    fd = FlightData()
    airport_departures = fd.get_airport_departures(iata, page=1, limit=10)
    return jsonify(airport_departures)
Example #5
0
def realtime_airport_arrivals(iata):
    fd = FlightData()
    airport_arrivals = fd.get_airport_arrivals(iata, page=1, limit=10)
    airport_departures = fd.get_airport_departures(iata, page=1, limit=10)
    airport_flights = airport_arrivals + airport_departures
    return jsonify(airport_flights)