Changeset 919:2ce8ca39525b for src/mlx/web.py
- Timestamp:
- 03/24/19 08:15:59 (5 years ago)
- Branch:
- python3
- hg-Phase:
- (<MercurialRepository 1 'hg:/home/ivaradi/mlx/hg' '/'>, 'public')
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mlx/web.py
r859 r919 1 1 2 import const3 import util4 from rpc import Registration5 import rpc6 import rpccommon7 8 from common import MAVA_BASE_URL9 from pirep import PIREP2 from . import const 3 from . import util 4 from .rpc import Registration 5 from . import rpc 6 from . import rpccommon 7 8 from .common import MAVA_BASE_URL 9 from .pirep import PIREP 10 10 11 11 import threading 12 12 import sys 13 import urllib 14 import urllib 213 import urllib.request, urllib.parse, urllib.error 14 import urllib.request, urllib.error, urllib.parse 15 15 import hashlib 16 16 import time … … 19 19 import traceback 20 20 import xml.sax 21 import xmlrpc lib22 import HTMLParser21 import xmlrpc.client 22 import html.parser 23 23 24 24 #--------------------------------------------------------------------------------------- … … 160 160 161 161 date = readline(f) 162 print "web.BookedFlight.readFromWeb: date:", date162 print("web.BookedFlight.readFromWeb: date:", date) 163 163 if date=="0000-00-00": date = "0001-01-01" 164 164 … … 233 233 234 234 if not lineOK: 235 print 236 (lineNumber,) 235 print("web.BookedFlight.readFromFile: line %d is invalid" % \ 236 (lineNumber,)) 237 237 238 238 line = f.readline() … … 290 290 def writeIntoFile(self, f): 291 291 """Write the flight into a file.""" 292 print >> f, "callsign=%s" % (self.callsign,)292 print("callsign=%s" % (self.callsign,), file=f) 293 293 date = self.departureTime.date() 294 print >> f, "date=%04d-%02d-%0d" % (date.year, date.month, date.day)295 print >> f, "dep_airport=%s" % (self.departureICAO,)296 print >> f, "dest_airport=%s" % (self.arrivalICAO,)297 print >> f,"planecode=%s" % \298 (BookedFlight.TYPE2TYPECODE[self.aircraftType],) 299 print >> f, "planetype=%s" % (self.aircraftTypeName,)300 print >> f, "tail_nr=%s" % (self.tailNumber,)301 print >> f, "passenger=%d" % (self.numPassengers,)302 print >> f, "crew=%d" % (self.numCrew,)303 print >> f, "bag=%d" % (self.bagWeight,)304 print >> f, "cargo=%d" % (self.cargoWeight,)305 print >> f, "mail=%d" % (self.mailWeight,)306 print >> f, "flight_route=%s" % (self.route,)294 print("date=%04d-%02d-%0d" % (date.year, date.month, date.day), file=f) 295 print("dep_airport=%s" % (self.departureICAO,), file=f) 296 print("dest_airport=%s" % (self.arrivalICAO,), file=f) 297 print("planecode=%s" % \ 298 (BookedFlight.TYPE2TYPECODE[self.aircraftType],), file=f) 299 print("planetype=%s" % (self.aircraftTypeName,), file=f) 300 print("tail_nr=%s" % (self.tailNumber,), file=f) 301 print("passenger=%d" % (self.numPassengers,), file=f) 302 print("crew=%d" % (self.numCrew,), file=f) 303 print("bag=%d" % (self.bagWeight,), file=f) 304 print("cargo=%d" % (self.cargoWeight,), file=f) 305 print("mail=%d" % (self.mailWeight,), file=f) 306 print("flight_route=%s" % (self.route,), file=f) 307 307 departureTime = self.departureTime 308 print >> f,"departure_time=%02d\\:%02d\\:%02d" % \309 (departureTime.hour, departureTime.minute, departureTime.second) 308 print("departure_time=%02d\\:%02d\\:%02d" % \ 309 (departureTime.hour, departureTime.minute, departureTime.second), file=f) 310 310 arrivalTime = self.arrivalTime 311 print >> f,"arrival_time=%02d\\:%02d\\:%02d" % \312 (arrivalTime.hour, arrivalTime.minute, arrivalTime.second) 313 print >> f, "foglalas_id=%s" % ("0" if self.id is None else self.id,)311 print("arrival_time=%02d\\:%02d\\:%02d" % \ 312 (arrivalTime.hour, arrivalTime.minute, arrivalTime.second), file=f) 313 print("foglalas_id=%s" % ("0" if self.id is None else self.id,), file=f) 314 314 315 315 def _readAircraftType(self, f): … … 364 364 365 365 except: 366 print >> sys.stderr, "Plane string is invalid: '" + s + "'"366 print("Plane string is invalid: '" + s + "'", file=sys.stderr) 367 367 self.tailNumber = None 368 368 … … 470 470 #------------------------------------------------------------------------------ 471 471 472 class PilotsWebNOTAMsParser( HTMLParser.HTMLParser):472 class PilotsWebNOTAMsParser(html.parser.HTMLParser): 473 473 """XML handler for the NOTAM query results on the PilotsWeb website.""" 474 474 def __init__(self): 475 475 """Construct the handler.""" 476 HTMLParser.HTMLParser.__init__(self)476 html.parser.HTMLParser.__init__(self) 477 477 478 478 self._notams = [] … … 513 513 try: 514 514 notam = self._parseCurrentNOTAM2() 515 except Exception ,e:516 print "Error parsing current NOTAM: " + str(e)515 except Exception as e: 516 print("Error parsing current NOTAM: " + str(e)) 517 517 518 518 if notam is None: 519 print "Could not parse NOTAM: " + self._currentNOTAM519 print("Could not parse NOTAM: " + self._currentNOTAM) 520 520 if self._currentNOTAM: 521 521 self._notams.append(self._currentNOTAM + "\n") … … 526 526 """Parse the current NOTAM, if possible, and return a NOTAM object.""" 527 527 lines = self._currentNOTAM.splitlines() 528 lines = map(lambda line: line.strip(), lines)528 lines = [line.strip() for line in lines] 529 529 530 530 if len(lines)<4: … … 579 579 """Parse the current NOTAM with a second, more flexible method.""" 580 580 lines = self._currentNOTAM.splitlines() 581 lines = map(lambda line: line.strip(), lines)581 lines = [line.strip() for line in lines] 582 582 583 583 if not lines: … … 592 592 lines = lines[:-1] 593 593 594 lines = map(lambda line: line.strip(), lines)594 lines = [line.strip() for line in lines] 595 595 contents = " ".join(lines).split() 596 596 … … 653 653 """Get a representation of the result.""" 654 654 s = "<Result:" 655 for (key, value) in self.__dict__.ite ritems():656 s += " " + key + "=" + unicode(value)655 for (key, value) in self.__dict__.items(): 656 s += " " + key + "=" + str(value) 657 657 s += ">" 658 658 return s … … 688 688 result = self.run() 689 689 returned = True 690 except Exception ,e:690 except Exception as e: 691 691 traceback.print_exc() 692 692 result = e … … 695 695 try: 696 696 self._callback(returned, result) 697 except Exception ,e:698 print >> sys.stderr, "web.Handler.Request.perform: callback throwed an exception: " + util.utf2unicode(str(e))697 except Exception as e: 698 print("web.Handler.Request.perform: callback throwed an exception: " + util.utf2unicode(str(e)), file=sys.stderr) 699 699 #traceback.print_exc() 700 700 … … 769 769 result = Result() 770 770 771 f = urllib 2.urlopen(url, timeout = 10.0)771 f = urllib.request.urlopen(url, timeout = 10.0) 772 772 773 773 status = readline(f) … … 880 880 url = MAVA_BASE_URL + "/onlinegates_get.php" 881 881 882 f = urllib 2.urlopen(url, timeout = 10.0)882 f = urllib.request.urlopen(url, timeout = 10.0) 883 883 result = Result() 884 884 result.fleet = Fleet(f) … … 922 922 gateNumber = self._gateNumber if self._gateNumber else "" 923 923 924 data = urllib. urlencode([("lajstrom", self._tailNumber),924 data = urllib.parse.urlencode([("lajstrom", self._tailNumber), 925 925 ("status", status), 926 926 ("kapu", gateNumber)]) 927 927 928 f = urllib 2.urlopen(url, data, timeout = 10.0)928 f = urllib.request.urlopen(url, data, timeout = 10.0) 929 929 line = readline(f) 930 930 … … 983 983 url = "http://notams.euroutepro.com/notams.xml" 984 984 985 f = urllib 2.urlopen(url, timeout = 10.0)985 f = urllib.request.urlopen(url, timeout = 10.0) 986 986 try: 987 987 xmlParser.parse(f) … … 1012 1012 (icao.upper(),) 1013 1013 1014 f = urllib 2.urlopen(url, timeout = 10.0)1014 f = urllib.request.urlopen(url, timeout = 10.0) 1015 1015 try: 1016 1016 data = f.read(16384) … … 1023 1023 return parser.getNOTAMs() 1024 1024 1025 except Exception ,e:1025 except Exception as e: 1026 1026 traceback.print_exc() 1027 print 1028 (icao, str(e)) 1027 print("mlx.web.GetNOTAMs.getPilotsWebNOTAMs: failed to get NOTAMs for '%s': %s" % \ 1028 (icao, str(e))) 1029 1029 return None 1030 1030 … … 1042 1042 """Perform the retrieval opf the METARs.""" 1043 1043 url = "http://www.aviationweather.gov/adds/dataserver_current/httpparam?" 1044 data = urllib. urlencode([ ("dataSource" , "metars"),1044 data = urllib.parse.urlencode([ ("dataSource" , "metars"), 1045 1045 ("requestType", "retrieve"), 1046 1046 ("format", "csv"), … … 1049 1049 ("mostRecentForEachStation", "constraint")]) 1050 1050 url += data 1051 f = urllib 2.urlopen(url, timeout = 10.0)1051 f = urllib.request.urlopen(url, timeout = 10.0) 1052 1052 try: 1053 1053 result = Result() … … 1128 1128 data["insdate"] = datetime.date.today().strftime("%Y-%m-%d") 1129 1129 1130 postData = urllib. urlencode(data)1131 f = urllib 2.urlopen(url, postData, timeout = 10.0)1130 postData = urllib.parse.urlencode(data) 1131 f = urllib.request.urlopen(url, postData, timeout = 10.0) 1132 1132 try: 1133 1133 result = Result() 1134 1134 line = f.readline().strip() 1135 print "PIREP result from website:", line1135 print("PIREP result from website:", line) 1136 1136 result.success = line=="OK" 1137 1137 result.alreadyFlown = line=="MARVOLT" … … 1178 1178 def run(self): 1179 1179 """Perform the sending of the ACARS.""" 1180 print "Sending the online ACARS"1180 print("Sending the online ACARS") 1181 1181 1182 1182 url = MAVA_BASE_URL + "/acars2/acarsonline.php" … … 1204 1204 data["event"] = acars.getEventText() 1205 1205 1206 f = urllib 2.urlopen(url, urllib.urlencode(data), timeout = 10.0)1206 f = urllib.request.urlopen(url, urllib.parse.urlencode(data), timeout = 10.0) 1207 1207 try: 1208 1208 result = Result() … … 1223 1223 def run(self): 1224 1224 """Perform the sending of the ACARS.""" 1225 print "Sending the online ACARS via JSON-RPC"1225 print("Sending the online ACARS via JSON-RPC") 1226 1226 1227 1227 self._client.updateOnlineACARS(self._acars) … … 1243 1243 def run(self): 1244 1244 """Perform the sending of the bug report.""" 1245 serverProxy = xmlrpc lib.ServerProxy("http://mlx.varadiistvan.hu/rpc")1245 serverProxy = xmlrpc.client.ServerProxy("http://mlx.varadiistvan.hu/rpc") 1246 1246 1247 1247 result = Result() … … 1254 1254 result.ticketID = serverProxy.ticket.create(self._summary, self._description, 1255 1255 attributes, True) 1256 print "Created ticket with ID:", result.ticketID1256 print("Created ticket with ID:", result.ticketID) 1257 1257 result.success = True 1258 1258 … … 1288 1288 1289 1289 pirepData = self._client.getPIREP(self._flightID) 1290 print "pirepData:", pirepData1290 print("pirepData:", pirepData) 1291 1291 1292 1292 bookedFlight = BookedFlight(self._flightID) … … 1512 1512 1513 1513 def callback(returned, result): 1514 print returned, unicode(result)1514 print(returned, str(result)) 1515 1515 1516 1516 handler = Handler()
Note:
See TracChangeset
for help on using the changeset viewer.