Index: src/mlx/pirep.py
===================================================================
--- src/mlx/pirep.py	(revision 778)
+++ src/mlx/pirep.py	(revision 829)
@@ -1,7 +1,9 @@
 
 from util import utf2unicode
+from flight import Flight
 
 import const
 import cPickle as pickle
+import calendar
 import datetime
 import time
@@ -36,4 +38,55 @@
         """Format the given timestamp for RPC."""
         return time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(t))
+
+    @staticmethod
+    def parseTimestampFromRPC(s):
+        """Format the given timestamp for RPC."""
+        dt = datetime.datetime.strptime(s, "%Y-%m-%d %H:%M:%S")
+        return calendar.timegm(dt.utctimetuple())
+
+    @staticmethod
+    def decodeFlightTypeText(s):
+        """Decode the given flight type text."""
+        for (flighType, text) in PIREP._flightTypes.iteritems():
+            if s==text:
+                return flighType
+        return const.FLIGHTYPE_SCHEDULED
+
+    @staticmethod
+    def parseLogFromRPC(log):
+        """Parse the given log coming from the RPC."""
+        index = 0
+        entries = []
+
+        inTimeStr = False
+        inEntry = False
+
+        timestr = ""
+        entry = ""
+
+        while index<len(log):
+            c = log[index]
+            index += 1
+
+            if c==']':
+                if inEntry:
+                    entries.append((timestr, entry))
+                    timestr = ""
+                    entry = ""
+
+                inTimeStr = False
+                inEntry = False
+            elif not inTimeStr and not inEntry:
+                if c=='[':
+                    if timestr:
+                        inEntry = True
+                    else:
+                        inTimeStr = True
+            elif inTimeStr:
+                timestr += c
+            elif inEntry:
+                entry += c
+
+        return entries
 
     @staticmethod
@@ -61,4 +114,7 @@
     def __init__(self, flight):
         """Initialize the PIREP from the given flight."""
+        if flight is None:
+            return
+
         self.bookedFlight = flight.bookedFlight
 
@@ -102,4 +158,89 @@
         self.logLines = logger.lines
         self.faultLineIndexes = logger.faultLineIndexes
+
+    def setupFromPIREPData(self, pirepData, bookedFlight):
+
+        self.bookedFlight = bookedFlight
+
+        self.numCrew = int(pirepData["numCrew"])
+        self.numPassengers = int(pirepData["numPassengers"])
+        self.bagWeight = int(pirepData["bagWeight"])
+        self.cargoWeight = int(pirepData["cargoWeight"])
+        self.mailWeight = int(pirepData["mailWeight"])
+
+        self.filedCruiseAltitude = int(pirepData["filedCruiseLevel"][2:])*100
+        cruiseLevel = pirepData["cruiseLevel"]
+        if cruiseLevel:
+            self.cruiseAltitude = int(cruiseLevel[2:])*100
+        else:
+            self.cruiseAltitude = self.filedCruiseAltitude
+        self.route = pirepData["route"]
+
+        self.departureMETAR = pirepData["departureMETAR"]
+        self.arrivalMETAR = pirepData["arrivalMETAR"]
+
+        self.departureRunway = pirepData["departureRunway"]
+        self.sid = pirepData["sid"]
+
+        star = pirepData["star"].split(",")
+        self.star = star[0]
+        self.star.strip()
+
+        if len(star)>1:
+            self.transition = star[1]
+            self.transition.strip()
+        else:
+            self.transition = ""
+        self.approachType = pirepData["approachType"]
+        self.arrivalRunway = pirepData["arrivalRunway"]
+
+        self.flightType = PIREP.decodeFlightTypeText(pirepData["flightType"])
+        self.online = int(pirepData["online"])!=0
+
+        self.comments = pirepData["comments"]
+        self.flightDefects = pirepData["flightDefects"]
+        self.delayCodes = pirepData["timeComment"]
+        if self.delayCodes=="UTC":
+            self.delayCodes = ""
+
+        flightDate = pirepData["flightDate"] + " "
+
+        self.blockTimeStart = \
+          PIREP.parseTimestampFromRPC(flightDate + pirepData["blockTimeStart"])
+        self.flightTimeStart = \
+          PIREP.parseTimestampFromRPC(flightDate + pirepData["flightTimeStart"])
+        self.flightTimeEnd = \
+          PIREP.parseTimestampFromRPC(flightDate + pirepData["flightTimeEnd"])
+        self.blockTimeEnd = \
+          PIREP.parseTimestampFromRPC(flightDate + pirepData["blockTimeEnd"])
+        self.flownDistance = float(pirepData["flownDistance"])
+        self.fuelUsed = float(pirepData["fuelUsed"])
+
+        # logger = flight.logger
+        self.rating = float(pirepData["rating"])
+
+        log = pirepData["log"]
+
+        self.logLines = PIREP.parseLogFromRPC(log)[1:]
+        if self.logLines and \
+           (self.logLines[0][0]=="LOGGER NG LOG" or
+            self.logLines[0][0]=="MAVA LOGGER X"):
+            self.logLines = self.logLines[1:]
+        numLogLines = len(self.logLines)
+
+        lastFaultLineIndex = 0
+        self.faultLineIndexes = []
+        for ratingText in pirepData["ratingText"].splitlines()[:-1]:
+            faultLines = PIREP.parseLogFromRPC(ratingText)
+            for (timeStr, entry) in faultLines:
+                for i in range(lastFaultLineIndex, numLogLines-1):
+                    if timeStr>=self.logLines[i][0] and \
+                       timeStr<self.logLines[i+1][0]:
+                        self.logLines = self.logLines[:i+1] + \
+                          [(timeStr, entry)] + self.logLines[i+1:]
+                        self.faultLineIndexes.append(i+1)
+                        lastFaultLineIndex = i+1
+                        numLogLines += 1
+                        break
 
     @property
Index: src/mlx/rpc.py
===================================================================
--- src/mlx/rpc.py	(revision 824)
+++ src/mlx/rpc.py	(revision 829)
@@ -340,4 +340,10 @@
                           self._server.setCheckFlightPassed(sessionID, type))
 
+    def getPIREP(self, flightID):
+        """Get the PIREP data for the flight with the given ID."""
+        value = self._performCall(lambda sessionID:
+                                  self._server.getPIREP(sessionID, flightID))
+        return value
+
     def reflyFlights(self, flightIDs):
         """Mark the flights with the given IDs for reflying."""
Index: src/mlx/web.py
===================================================================
--- src/mlx/web.py	(revision 824)
+++ src/mlx/web.py	(revision 829)
@@ -7,4 +7,5 @@
 
 from common import MAVA_BASE_URL
+from pirep import PIREP
 
 import threading
@@ -257,4 +258,33 @@
             self.aircraftTypeName = \
                 BookedFlight.TYPE2TYPECODE[self.aircraftType]
+
+    def setupFromPIREPData(self, pirepData):
+        """Setup the booked flight from the given PIREP data."""
+        bookedFlightData = pirepData["bookedFlight"]
+
+        self.callsign = bookedFlightData["callsign"]
+
+        date = bookedFlightData["date"]
+
+        departureTime = bookedFlightData["departureTime"]
+        self.departureTime = BookedFlight.getDateTime(date, departureTime)
+
+        arrivalTime = bookedFlightData["arrivalTime"]
+        self.arrivalTime = BookedFlight.getDateTime(date, arrivalTime)
+        if self.arrivalTime<self.departureTime:
+            self.arrivalTime += datetime.timedelta(days = 1)
+
+        self.departureICAO = bookedFlightData["departureICAO"]
+        self.arrivalICAO = bookedFlightData["arrivalICAO"]
+
+        self.aircraftType = \
+          self._decodeAircraftType(bookedFlightData["aircraftType"])
+        self.tailNumber = bookedFlightData["tailNumber"]
+        self.numPassengers = int(bookedFlightData["numPassengers"])
+        self.numCrew = int(bookedFlightData["numCrew"])
+        self.bagWeight = int(bookedFlightData["bagWeight"])
+        self.cargoWeight = int(bookedFlightData["cargoWeight"])
+        self.mailWeight = int(bookedFlightData["mailWeight"])
+        self.route = bookedFlightData["route"]
 
     def writeIntoFile(self, f):
@@ -1242,4 +1272,28 @@
 #------------------------------------------------------------------------------
 
+class GetPIREP(RPCRequest):
+    """A request to retrieve the PIREP of a certain flight."""
+    def __init__(self, client, callback, flightID):
+        """Construct the request."""
+        super(GetPIREP, self).__init__(client, callback)
+        self._flightID = flightID
+
+    def run(self):
+        """Perform the update."""
+        result = Result()
+
+        pirepData = self._client.getPIREP(self._flightID)
+        print "pirepData:", pirepData
+
+        bookedFlight = BookedFlight()
+        bookedFlight.setupFromPIREPData(pirepData)
+
+        result.pirep = PIREP(None)
+        result.pirep.setupFromPIREPData(pirepData, bookedFlight)
+
+        return result
+
+#------------------------------------------------------------------------------
+
 class ReflyFlights(RPCRequest):
     """A request to mark certain flights for reflying."""
@@ -1351,4 +1405,8 @@
                                               callback, aircraftType))
 
+    def getPIREP(self, callback, flightID):
+        """Query the PIREP for the given flight."""
+        self._addRequest(GetPIREP(self._rpcClient, callback, flightID))
+
     def reflyFlights(self, callback, flightIDs):
         """Mark the flights with the given IDs for reflying."""
