Ignore:
Timestamp:
12/30/16 15:37:51 (7 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
hg-Phase:
(<MercurialRepository 1 'hg:/home/ivaradi/mlx/hg' '/'>, 'public')
Message:

A PIREP can be queried from the server (re #307)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/web.py

    r824 r829  
    77
    88from common import MAVA_BASE_URL
     9from pirep import PIREP
    910
    1011import threading
     
    257258            self.aircraftTypeName = \
    258259                BookedFlight.TYPE2TYPECODE[self.aircraftType]
     260
     261    def setupFromPIREPData(self, pirepData):
     262        """Setup the booked flight from the given PIREP data."""
     263        bookedFlightData = pirepData["bookedFlight"]
     264
     265        self.callsign = bookedFlightData["callsign"]
     266
     267        date = bookedFlightData["date"]
     268
     269        departureTime = bookedFlightData["departureTime"]
     270        self.departureTime = BookedFlight.getDateTime(date, departureTime)
     271
     272        arrivalTime = bookedFlightData["arrivalTime"]
     273        self.arrivalTime = BookedFlight.getDateTime(date, arrivalTime)
     274        if self.arrivalTime<self.departureTime:
     275            self.arrivalTime += datetime.timedelta(days = 1)
     276
     277        self.departureICAO = bookedFlightData["departureICAO"]
     278        self.arrivalICAO = bookedFlightData["arrivalICAO"]
     279
     280        self.aircraftType = \
     281          self._decodeAircraftType(bookedFlightData["aircraftType"])
     282        self.tailNumber = bookedFlightData["tailNumber"]
     283        self.numPassengers = int(bookedFlightData["numPassengers"])
     284        self.numCrew = int(bookedFlightData["numCrew"])
     285        self.bagWeight = int(bookedFlightData["bagWeight"])
     286        self.cargoWeight = int(bookedFlightData["cargoWeight"])
     287        self.mailWeight = int(bookedFlightData["mailWeight"])
     288        self.route = bookedFlightData["route"]
    259289
    260290    def writeIntoFile(self, f):
     
    12421272#------------------------------------------------------------------------------
    12431273
     1274class GetPIREP(RPCRequest):
     1275    """A request to retrieve the PIREP of a certain flight."""
     1276    def __init__(self, client, callback, flightID):
     1277        """Construct the request."""
     1278        super(GetPIREP, self).__init__(client, callback)
     1279        self._flightID = flightID
     1280
     1281    def run(self):
     1282        """Perform the update."""
     1283        result = Result()
     1284
     1285        pirepData = self._client.getPIREP(self._flightID)
     1286        print "pirepData:", pirepData
     1287
     1288        bookedFlight = BookedFlight()
     1289        bookedFlight.setupFromPIREPData(pirepData)
     1290
     1291        result.pirep = PIREP(None)
     1292        result.pirep.setupFromPIREPData(pirepData, bookedFlight)
     1293
     1294        return result
     1295
     1296#------------------------------------------------------------------------------
     1297
    12441298class ReflyFlights(RPCRequest):
    12451299    """A request to mark certain flights for reflying."""
     
    13511405                                              callback, aircraftType))
    13521406
     1407    def getPIREP(self, callback, flightID):
     1408        """Query the PIREP for the given flight."""
     1409        self._addRequest(GetPIREP(self._rpcClient, callback, flightID))
     1410
    13531411    def reflyFlights(self, callback, flightIDs):
    13541412        """Mark the flights with the given IDs for reflying."""
Note: See TracChangeset for help on using the changeset viewer.