Ignore:
Timestamp:
02/28/13 18:56:30 (11 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

Added support for the BAe 146-200 aircraft type (re #182)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/web.py

    r401 r443  
    6363                      "TU3"  : const.AIRCRAFT_T134,
    6464                      "TU5"  : const.AIRCRAFT_T154,
    65                       "YK4"  : const.AIRCRAFT_YK40 }
     65                      "YK4"  : const.AIRCRAFT_YK40,
     66                      "146"  : const.AIRCRAFT_B462 }
    6667
    6768    TYPE2TYPECODE = { const.AIRCRAFT_B736  : "736",
     
    8081                      const.AIRCRAFT_T134  : "TU3",
    8182                      const.AIRCRAFT_T154  : "TU5",
    82                       const.AIRCRAFT_YK40  : "YK4" }
     83                      const.AIRCRAFT_YK40  : "YK4",
     84                      const.AIRCRAFT_B462  : "146" }
    8385
    8486    @staticmethod
     
    115117        departureTime = readline(f)
    116118        self.departureTime = BookedFlight.getDateTime(date, departureTime)
    117                                                
     119
    118120        arrivalTime = readline(f)
    119121        self.arrivalTime = BookedFlight.getDateTime(date, arrivalTime)
     
    130132        departureTime = None
    131133        arrivalTime = None
    132        
     134
    133135        line = f.readline()
    134         lineNumber = 0   
     136        lineNumber = 0
    135137        while line:
    136138            lineNumber += 1
    137139            line = line.strip()
    138            
     140
    139141            hashIndex = line.find("#")
    140142            if hashIndex>=0: line = line[:hashIndex]
     
    142144                equalIndex = line.find("=")
    143145                lineOK = equalIndex>0
    144                
     146
    145147                if lineOK:
    146                     key = line[:equalIndex].strip()                   
     148                    key = line[:equalIndex].strip()
    147149                    value = line[equalIndex+1:].strip().replace("\:", ":")
    148                    
     150
    149151                    lineOK = key and value
    150152
     
    196198            self.aircraftTypeName = \
    197199                BookedFlight.TYPE2TYPECODE[self.aircraftType]
    198            
     200
    199201    def writeIntoFile(self, f):
    200202        """Write the flight into a file."""
     
    235237        else:
    236238            raise Exception("Invalid aircraft type code: '" + typeCode + "'")
    237        
     239
    238240    def __repr__(self):
    239241        """Get a representation of the flight."""
     
    248250        s += ">"
    249251        return s
    250        
     252
    251253#------------------------------------------------------------------------------
    252254
     
    279281    def __repr__(self):
    280282        """Get the representation of the plane object."""
    281         s = "<Plane: %s %s" % (self.tailNumber, 
     283        s = "<Plane: %s %s" % (self.tailNumber,
    282284                               "home" if self.status==const.PLANE_HOME else \
    283285                               "away" if self.status==const.PLANE_AWAY else \
     
    288290        s += ">"
    289291        return s
    290        
     292
    291293
    292294#------------------------------------------------------------------------------
     
    323325                gateNumbers.add(p.gateNumber)
    324326        return gateNumbers
    325    
     327
    326328    def updatePlane(self, tailNumber, status, gateNumber = None):
    327329        """Update the status of the given plane."""
     
    330332            plane.status = status
    331333            plane.gateNumber = gateNumber
    332    
     334
    333335    def __iter__(self):
    334336        """Get an iterator over the planes."""
    335337        for plane in self._planes.itervalues():
    336338            yield plane
    337        
     339
    338340    def __getitem__(self, tailNumber):
    339341        """Get the plane with the given tail number.
     
    345347        """Get the representation of the fleet object."""
    346348        return self._planes.__repr__()
    347        
     349
    348350#------------------------------------------------------------------------------
    349351
     
    371373        s += ">"
    372374        return s
    373    
     375
    374376#------------------------------------------------------------------------------
    375377
     
    389391           "E" not in attrs or not attrs["E"]:
    390392            return
    391        
     393
    392394        icao = attrs["A"]
    393395        if icao not in self._notams:
    394396            return
    395        
     397
    396398        begin = datetime.datetime.strptime(attrs["B"], "%Y-%m-%d %H:%M:%S")
    397399
    398400        c = attrs["C"] if "C" in attrs else None
    399401        end = datetime.datetime.strptime(c, "%Y-%m-%d %H:%M:%S") if c else None
    400        
     402
    401403        permanent = attrs["C_flag"]=="PERM" if "C_flag" in attrs else False
    402        
     404
    403405        repeatCycle = attrs["D"] if "D" in attrs else None
    404406
     
    473475    """A login request."""
    474476    iso88592decoder = codecs.getdecoder("iso-8859-2")
    475    
     477
    476478    def __init__(self, callback, pilotID, password, entranceExam):
    477479        """Construct the login request with the given pilot ID and
     
    488490        md5.update(self._pilotID)
    489491        pilotID = md5.hexdigest()
    490        
     492
    491493        md5 = hashlib.md5()
    492494        md5.update(self._password)
     
    524526                result.pilotName = self.iso88592decoder(readline(f))[0]
    525527                result.exams = readline(f)
    526                
     528
    527529                while True:
    528530                    line = readline(f)
     
    540542
    541543        return result
    542        
     544
    543545#------------------------------------------------------------------------------
    544546
    545547class GetFleet(Request):
    546548    """Request to get the fleet from the website."""
    547    
     549
    548550    def __init__(self, callback):
    549551        """Construct the fleet request."""
     
    558560        result.fleet = Fleet(f)
    559561        f.close()
    560        
     562
    561563        return result
    562564
     
    585587                                 ("status", status),
    586588                                 ("kapu", gateNumber)])
    587        
     589
    588590        f = urllib2.urlopen(url, data, timeout = 10.0)
    589591        line = readline(f)
    590        
     592
    591593        result = Result()
    592594        result.success = line == "OK"
    593595
    594596        return result
    595            
     597
    596598#------------------------------------------------------------------------------
    597599
     
    628630
    629631class GetMETARs(Request):
    630     """Get the METARs from the NOAA website for certain airport ICAOs."""   
     632    """Get the METARs from the NOAA website for certain airport ICAOs."""
    631633
    632634    def __init__(self, callback, airports):
     
    639641        url = "http://www.aviationweather.gov/adds/dataserver_current/httpparam?"
    640642        data = urllib.urlencode([ ("dataSource" , "metars"),
    641                                   ("requestType",  "retrieve"), 
     643                                  ("requestType",  "retrieve"),
    642644                                  ("format", "csv"),
    643645                                  ("stationString", " ".join(self._airports)),
     
    652654                if len(line)>5 and line[4]==' ':
    653655                    icao = line[0:4]
    654                     if icao in self._airports:                       
     656                    if icao in self._airports:
    655657                        result.metars[icao] = line.strip().split(",")[0]
    656658        finally:
     
    696698        data["bag"] = str(pirep.bagWeight)
    697699        data["mail"] = str(pirep.mailWeight)
    698        
     700
    699701        data["flttype"] = SendPIREP._flightTypes[pirep.flightType]
    700702        data["onoff"] = "1" if pirep.online else "0"
     
    742744            f.close()
    743745
    744         return result   
     746        return result
    745747#------------------------------------------------------------------------------
    746748
     
    757759        """Perform the sending of the ACARS."""
    758760        print "Sending the online ACARS"
    759        
     761
    760762        url = "http://www.virtualairlines.hu/acars2/acarsonline.php"
    761763
     
    766768        data["pid"] = acars.pid
    767769        data["pilot"] = SendACARS._latin2Encoder(acars.pilotName)[0]
    768    
     770
    769771        data["pass"] = str(bookedFlight.numPassengers)
    770772        data["callsign"] = bookedFlight.callsign
    771773        data["airplane"] = bookedFlight.aircraftTypeName
    772774        data["from"] = bookedFlight.departureICAO
    773         data["to"] = bookedFlight.arrivalICAO       
     775        data["to"] = bookedFlight.arrivalICAO
    774776        data["lajstrom"] = bookedFlight.tailNumber
    775777
     
    779781        data["altitude"] = str(acars.state.altitude)
    780782        data["speed"] = str(acars.state.groundSpeed)
    781        
     783
    782784        data["event"] = acars.getEventText()
    783785
     
    788790            f.close()
    789791
    790         return result   
     792        return result
    791793
    792794#------------------------------------------------------------------------------
     
    813815        """Enqueue a fleet retrieval request."""
    814816        self._addRequest(GetFleet(callback))
    815        
     817
    816818    def updatePlane(self, callback, tailNumber, status, gateNumber = None):
    817         """Update the status of the given plane."""       
     819        """Update the status of the given plane."""
    818820        self._addRequest(UpdatePlane(callback, tailNumber, status, gateNumber))
    819821
     
    821823        """Get the NOTAMs for the given two airports."""
    822824        self._addRequest(GetNOTAMs(callback, departureICAO, arrivalICAO))
    823        
     825
    824826    def getMETARs(self, callback, airports):
    825827        """Get the METARs for the given airports."""
     
    833835        """Send the given ACARS"""
    834836        self._addRequest(SendACARS(callback, acars))
    835        
     837
    836838    def run(self):
    837839        """Process the requests."""
     
    844846
    845847            request.perform()
    846    
     848
    847849    def _addRequest(self, request):
    848850        """Add the given request to the queue."""
     
    855857if __name__ == "__main__":
    856858    import time
    857    
     859
    858860    def callback(returned, result):
    859861        print returned, unicode(result)
    860        
     862
    861863    handler = Handler()
    862864    handler.start()
     
    866868    # Plane: HA-LEG home (gate 67)
    867869    #handler.updatePlane(callback, "HA-LQC", const.PLANE_AWAY, "72")
    868     #time.sleep(3)   
     870    #time.sleep(3)
    869871    #handler.getFleet(callback)
    870872    #time.sleep(3)
     
    873875    #handler.getMETARs(callback, ["LHBP", "EPWA"])
    874876    #time.sleep(5)
    875    
     877
    876878    handler.updatePlane(callback, "HA-LON", const.PLANE_AWAY, "")
    877     time.sleep(3)   
    878 
    879 #------------------------------------------------------------------------------
     879    time.sleep(3)
     880
     881#------------------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.