Changeset 66:d288a492befe
- Timestamp:
- 04/09/12 06:55:01 (13 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mlx/web.py
r63 r66 10 10 import urllib2 11 11 import hashlib 12 import time 12 13 import datetime 13 14 import codecs 15 import re 14 16 import xml.sax 15 17 … … 426 428 427 429 def run(self): 428 """Perform the plane update."""430 """Perform the retrieval of the NOTAMs.""" 429 431 xmlParser = xml.sax.make_parser() 430 432 notamHandler = NOTAMHandler([self._departureICAO, self._arrivalICAO]) … … 447 449 #------------------------------------------------------------------------------ 448 450 451 class GetMETARs(Request): 452 """Get the METARs from the NOAA website for certain airport ICAOs.""" 453 454 # Regular expression matching a METAR line 455 metarLine = re.compile("^[A-Z0-9]{4} ") 456 457 def __init__(self, callback, airports): 458 """Construct the request for the given airports.""" 459 super(GetMETARs, self).__init__(callback) 460 self._airports = airports 461 462 def run(self): 463 """Perform the retrieval opf the METARs.""" 464 tm = time.gmtime() 465 url = "http://weather.noaa.gov/pub/data/observations/metar/cycles/%02dZ.TXT" % \ 466 (tm.tm_hour,) 467 f = urllib2.urlopen(url) 468 try: 469 result = Result() 470 result.metars = {} 471 for line in iter(f.readline, ""): 472 if len(line)>5 and line[4]==' ': 473 icao = line[0:4] 474 if icao in self._airports: 475 result.metars[icao] = line.strip() 476 finally: 477 f.close() 478 479 return result 480 481 #------------------------------------------------------------------------------ 482 449 483 class Handler(threading.Thread): 450 484 """The handler for the web services. … … 476 510 """Get the NOTAMs for the given two airports.""" 477 511 self._addRequest(GetNOTAMs(callback, departureICAO, arrivalICAO)) 512 513 def getMETARs(self, callback, airports): 514 """Get the METARs for the given airports.""" 515 self._addRequest(GetMETARs(callback, airports)) 478 516 479 517 def run(self): … … 513 551 #time.sleep(3) 514 552 515 handler.getNOTAMs(callback, "LHBP", "EPWA") 516 time.sleep(3) 553 #handler.getNOTAMs(callback, "LHBP", "EPWA") 554 handler.getMETARs(callback, ["LHBP", "EPWA"]) 555 time.sleep(5) 517 556 518 557
Note:
See TracChangeset
for help on using the changeset viewer.