Changeset 312:77203c978bf5


Ignore:
Timestamp:
08/19/12 05:12:20 (12 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

Removed the second instance of SendPIREP

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/web.py

    r305 r312  
    671671
    672672    def __init__(self, callback, pirep):
    673         """Construct the request for the given PIREP."""
     673        """Construct the sending of the PIREP."""
    674674        super(SendPIREP, self).__init__(callback)
    675675        self._pirep = pirep
     
    741741
    742742        return result   
    743 
    744 #------------------------------------------------------------------------------
    745 
    746 class SendPIREP(Request):
    747     """A request to send a PIREP to the MAVA website."""
    748     _flightTypes = { const.FLIGHTTYPE_SCHEDULED : "SCHEDULED",
    749                      const.FLIGHTTYPE_OLDTIMER : "OT",
    750                      const.FLIGHTTYPE_VIP : "VIP",
    751                      const.FLIGHTTYPE_CHARTER : "CHARTER" }
    752 
    753     _latin2Encoder = codecs.getencoder("iso-8859-2")
    754 
    755     def __init__(self, callback, pirep):
    756         """Construct the request for the given PIREP."""
    757         super(SendPIREP, self).__init__(callback)
    758         self._pirep = pirep
    759 
    760     def run(self):
    761         """Perform the sending of the PIREP."""
    762         url = "http://www.virtualairlines.hu/malevacars.php"
    763 
    764         pirep = self._pirep
    765 
    766         data = {}
    767         data["acarsdata"] = pirep.getACARSText()
    768 
    769         bookedFlight = pirep.bookedFlight
    770         data["foglalas_id"] = bookedFlight.id
    771         data["repdate"] = bookedFlight.departureTime.date().strftime("%Y-%m-%d")
    772         data["fltnum"] = bookedFlight.callsign
    773         data["depap"] = bookedFlight.departureICAO
    774         data["arrap"] = bookedFlight.arrivalICAO
    775         data["pass"] = str(bookedFlight.numPassengers)
    776         data["crew"] = str(bookedFlight.numCrew)
    777         data["cargo"] = str(pirep.cargoWeight)
    778         data["bag"] = str(bookedFlight.bagWeight)
    779         data["mail"] = str(bookedFlight.mailWeight)
    780        
    781         data["flttype"] = SendPIREP._flightTypes[pirep.flightType]
    782         data["onoff"] = "1" if pirep.online else "0"
    783         data["bt_dep"] = util.getTimestampString(pirep.blockTimeStart)
    784         data["bt_arr"] = util.getTimestampString(pirep.blockTimeEnd)
    785         data["bt_dur"] = util.getTimeIntervalString(pirep.blockTimeEnd -
    786                                                     pirep.blockTimeStart)
    787         data["ft_dep"] = util.getTimestampString(pirep.flightTimeStart)
    788         data["ft_arr"] = util.getTimestampString(pirep.flightTimeEnd)
    789         data["ft_dur"] = util.getTimeIntervalString(pirep.flightTimeEnd -
    790                                                     pirep.flightTimeStart)
    791         data["timecomm"] = pirep.getTimeComment()
    792         data["fuel"] = "%.0f" % (pirep.fuelUsed,)
    793         data["dep_rwy"] = pirep.departureRunway
    794         data["arr_rwy"] = pirep.arrivalRunway
    795         data["wea_dep"] = pirep.departureMETAR
    796         data["wea_arr"] = pirep.arrivalMETAR
    797         data["alt"] = "FL%.0f" % (pirep.filedCruiseAltitude/100.0,)
    798         if pirep.filedCruiseAltitude!=pirep.cruiseAltitude:
    799             data["mod_alt"] = "FL%.0f" % (pirep.cruiseAltitude/100.0,)
    800         else:
    801             data["mod_alt"] = ""
    802         data["sid"] = pirep.sid
    803         data["navroute"] = pirep.route
    804         data["star"] = pirep.getSTAR()
    805         data["aprtype"] = pirep.approachType
    806         data["diff"] = "2"
    807         data["comment"] = SendPIREP._latin2Encoder(pirep.comments)[0]
    808         data["flightdefect"] = SendPIREP._latin2Encoder(pirep.flightDefects)[0]
    809         data["kritika"] = pirep.getRatingText()
    810         data["flightrating"] = "%.1f" % (max(0.0, pirep.rating),)
    811         data["distance"] = "%.3f" % (pirep.flownDistance,)
    812         data["insdate"] = datetime.date.today().strftime("%Y-%m-%d")
    813 
    814         f = urllib2.urlopen(url, urllib.urlencode(data), timeout = 10.0)
    815         try:
    816             result = Result()
    817             line = f.readline().strip()
    818             print "PIREP result from website:", line
    819             result.success = line=="OK"
    820             result.alreadyFlown = line=="MARVOLT"
    821             result.notAvailable = line=="NOMORE"
    822         finally:
    823             f.close()
    824 
    825         return result   
    826 
    827743#------------------------------------------------------------------------------
    828744
Note: See TracChangeset for help on using the changeset viewer.