- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mlx/web.py
r443 r401 63 63 "TU3" : const.AIRCRAFT_T134, 64 64 "TU5" : const.AIRCRAFT_T154, 65 "YK4" : const.AIRCRAFT_YK40, 66 "146" : const.AIRCRAFT_B462 } 65 "YK4" : const.AIRCRAFT_YK40 } 67 66 68 67 TYPE2TYPECODE = { const.AIRCRAFT_B736 : "736", … … 81 80 const.AIRCRAFT_T134 : "TU3", 82 81 const.AIRCRAFT_T154 : "TU5", 83 const.AIRCRAFT_YK40 : "YK4", 84 const.AIRCRAFT_B462 : "146" } 82 const.AIRCRAFT_YK40 : "YK4" } 85 83 86 84 @staticmethod … … 117 115 departureTime = readline(f) 118 116 self.departureTime = BookedFlight.getDateTime(date, departureTime) 119 117 120 118 arrivalTime = readline(f) 121 119 self.arrivalTime = BookedFlight.getDateTime(date, arrivalTime) … … 132 130 departureTime = None 133 131 arrivalTime = None 134 132 135 133 line = f.readline() 136 lineNumber = 0 134 lineNumber = 0 137 135 while line: 138 136 lineNumber += 1 139 137 line = line.strip() 140 138 141 139 hashIndex = line.find("#") 142 140 if hashIndex>=0: line = line[:hashIndex] … … 144 142 equalIndex = line.find("=") 145 143 lineOK = equalIndex>0 146 144 147 145 if lineOK: 148 key = line[:equalIndex].strip() 146 key = line[:equalIndex].strip() 149 147 value = line[equalIndex+1:].strip().replace("\:", ":") 150 148 151 149 lineOK = key and value 152 150 … … 198 196 self.aircraftTypeName = \ 199 197 BookedFlight.TYPE2TYPECODE[self.aircraftType] 200 198 201 199 def writeIntoFile(self, f): 202 200 """Write the flight into a file.""" … … 237 235 else: 238 236 raise Exception("Invalid aircraft type code: '" + typeCode + "'") 239 237 240 238 def __repr__(self): 241 239 """Get a representation of the flight.""" … … 250 248 s += ">" 251 249 return s 252 250 253 251 #------------------------------------------------------------------------------ 254 252 … … 281 279 def __repr__(self): 282 280 """Get the representation of the plane object.""" 283 s = "<Plane: %s %s" % (self.tailNumber, 281 s = "<Plane: %s %s" % (self.tailNumber, 284 282 "home" if self.status==const.PLANE_HOME else \ 285 283 "away" if self.status==const.PLANE_AWAY else \ … … 290 288 s += ">" 291 289 return s 292 290 293 291 294 292 #------------------------------------------------------------------------------ … … 325 323 gateNumbers.add(p.gateNumber) 326 324 return gateNumbers 327 325 328 326 def updatePlane(self, tailNumber, status, gateNumber = None): 329 327 """Update the status of the given plane.""" … … 332 330 plane.status = status 333 331 plane.gateNumber = gateNumber 334 332 335 333 def __iter__(self): 336 334 """Get an iterator over the planes.""" 337 335 for plane in self._planes.itervalues(): 338 336 yield plane 339 337 340 338 def __getitem__(self, tailNumber): 341 339 """Get the plane with the given tail number. … … 347 345 """Get the representation of the fleet object.""" 348 346 return self._planes.__repr__() 349 347 350 348 #------------------------------------------------------------------------------ 351 349 … … 373 371 s += ">" 374 372 return s 375 373 376 374 #------------------------------------------------------------------------------ 377 375 … … 391 389 "E" not in attrs or not attrs["E"]: 392 390 return 393 391 394 392 icao = attrs["A"] 395 393 if icao not in self._notams: 396 394 return 397 395 398 396 begin = datetime.datetime.strptime(attrs["B"], "%Y-%m-%d %H:%M:%S") 399 397 400 398 c = attrs["C"] if "C" in attrs else None 401 399 end = datetime.datetime.strptime(c, "%Y-%m-%d %H:%M:%S") if c else None 402 400 403 401 permanent = attrs["C_flag"]=="PERM" if "C_flag" in attrs else False 404 402 405 403 repeatCycle = attrs["D"] if "D" in attrs else None 406 404 … … 475 473 """A login request.""" 476 474 iso88592decoder = codecs.getdecoder("iso-8859-2") 477 475 478 476 def __init__(self, callback, pilotID, password, entranceExam): 479 477 """Construct the login request with the given pilot ID and … … 490 488 md5.update(self._pilotID) 491 489 pilotID = md5.hexdigest() 492 490 493 491 md5 = hashlib.md5() 494 492 md5.update(self._password) … … 526 524 result.pilotName = self.iso88592decoder(readline(f))[0] 527 525 result.exams = readline(f) 528 526 529 527 while True: 530 528 line = readline(f) … … 542 540 543 541 return result 544 542 545 543 #------------------------------------------------------------------------------ 546 544 547 545 class GetFleet(Request): 548 546 """Request to get the fleet from the website.""" 549 547 550 548 def __init__(self, callback): 551 549 """Construct the fleet request.""" … … 560 558 result.fleet = Fleet(f) 561 559 f.close() 562 560 563 561 return result 564 562 … … 587 585 ("status", status), 588 586 ("kapu", gateNumber)]) 589 587 590 588 f = urllib2.urlopen(url, data, timeout = 10.0) 591 589 line = readline(f) 592 590 593 591 result = Result() 594 592 result.success = line == "OK" 595 593 596 594 return result 597 595 598 596 #------------------------------------------------------------------------------ 599 597 … … 630 628 631 629 class GetMETARs(Request): 632 """Get the METARs from the NOAA website for certain airport ICAOs.""" 630 """Get the METARs from the NOAA website for certain airport ICAOs.""" 633 631 634 632 def __init__(self, callback, airports): … … 641 639 url = "http://www.aviationweather.gov/adds/dataserver_current/httpparam?" 642 640 data = urllib.urlencode([ ("dataSource" , "metars"), 643 ("requestType", "retrieve"), 641 ("requestType", "retrieve"), 644 642 ("format", "csv"), 645 643 ("stationString", " ".join(self._airports)), … … 654 652 if len(line)>5 and line[4]==' ': 655 653 icao = line[0:4] 656 if icao in self._airports: 654 if icao in self._airports: 657 655 result.metars[icao] = line.strip().split(",")[0] 658 656 finally: … … 698 696 data["bag"] = str(pirep.bagWeight) 699 697 data["mail"] = str(pirep.mailWeight) 700 698 701 699 data["flttype"] = SendPIREP._flightTypes[pirep.flightType] 702 700 data["onoff"] = "1" if pirep.online else "0" … … 744 742 f.close() 745 743 746 return result 744 return result 747 745 #------------------------------------------------------------------------------ 748 746 … … 759 757 """Perform the sending of the ACARS.""" 760 758 print "Sending the online ACARS" 761 759 762 760 url = "http://www.virtualairlines.hu/acars2/acarsonline.php" 763 761 … … 768 766 data["pid"] = acars.pid 769 767 data["pilot"] = SendACARS._latin2Encoder(acars.pilotName)[0] 770 768 771 769 data["pass"] = str(bookedFlight.numPassengers) 772 770 data["callsign"] = bookedFlight.callsign 773 771 data["airplane"] = bookedFlight.aircraftTypeName 774 772 data["from"] = bookedFlight.departureICAO 775 data["to"] = bookedFlight.arrivalICAO 773 data["to"] = bookedFlight.arrivalICAO 776 774 data["lajstrom"] = bookedFlight.tailNumber 777 775 … … 781 779 data["altitude"] = str(acars.state.altitude) 782 780 data["speed"] = str(acars.state.groundSpeed) 783 781 784 782 data["event"] = acars.getEventText() 785 783 … … 790 788 f.close() 791 789 792 return result 790 return result 793 791 794 792 #------------------------------------------------------------------------------ … … 815 813 """Enqueue a fleet retrieval request.""" 816 814 self._addRequest(GetFleet(callback)) 817 815 818 816 def updatePlane(self, callback, tailNumber, status, gateNumber = None): 819 """Update the status of the given plane.""" 817 """Update the status of the given plane.""" 820 818 self._addRequest(UpdatePlane(callback, tailNumber, status, gateNumber)) 821 819 … … 823 821 """Get the NOTAMs for the given two airports.""" 824 822 self._addRequest(GetNOTAMs(callback, departureICAO, arrivalICAO)) 825 823 826 824 def getMETARs(self, callback, airports): 827 825 """Get the METARs for the given airports.""" … … 835 833 """Send the given ACARS""" 836 834 self._addRequest(SendACARS(callback, acars)) 837 835 838 836 def run(self): 839 837 """Process the requests.""" … … 846 844 847 845 request.perform() 848 846 849 847 def _addRequest(self, request): 850 848 """Add the given request to the queue.""" … … 857 855 if __name__ == "__main__": 858 856 import time 859 857 860 858 def callback(returned, result): 861 859 print returned, unicode(result) 862 860 863 861 handler = Handler() 864 862 handler.start() … … 868 866 # Plane: HA-LEG home (gate 67) 869 867 #handler.updatePlane(callback, "HA-LQC", const.PLANE_AWAY, "72") 870 #time.sleep(3) 868 #time.sleep(3) 871 869 #handler.getFleet(callback) 872 870 #time.sleep(3) … … 875 873 #handler.getMETARs(callback, ["LHBP", "EPWA"]) 876 874 #time.sleep(5) 877 875 878 876 handler.updatePlane(callback, "HA-LON", const.PLANE_AWAY, "") 879 time.sleep(3) 880 881 #------------------------------------------------------------------------------ 877 time.sleep(3) 878 879 #------------------------------------------------------------------------------
Note:
See TracChangeset
for help on using the changeset viewer.