Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added .gitignore
Empty file.
3 changes: 3 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
Change Log
==========
metar 1.4.1
*) fixed indent levels to always be 4 spaces
*) using print() as function instead of command

metar 1.4
---------
Expand Down
66 changes: 34 additions & 32 deletions get_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,45 +10,47 @@
BASE_URL = "http://weather.noaa.gov/pub/data/observations/metar/stations"

def usage():
program = os.path.basename(sys.argv[0])
print "Usage: ",program,"<station> [ <station> ... ]"
print """Options:
<station> . a four-letter ICAO station code (e.g., "KEWR")
"""
sys.exit(1)
program = os.path.basename(sys.argv[0])
print("Usage: %s <station> [ <station> ... ]" % program)
options = """Options:
<station> . a four-letter ICAO station code (e.g., "KEWR")
"""
print(options)
sys.exit(1)


stations = []
debug = False

try:
opts, stations = getopt.getopt(sys.argv[1:], 'd')
for opt in opts:
if opt[0] == '-d':
debug = True
opts, stations = getopt.getopt(sys.argv[1:], 'd')
for opt in opts:
if opt[0] == '-d':
debug = True
except:
usage()

usage()
if not stations:
usage()
usage()

for name in stations:
url = "%s/%s.TXT" % (BASE_URL, name)
if debug:
sys.stderr.write("[ "+url+" ]")
try:
urlh = urllib.urlopen(url)
report = ''
for line in urlh:
if line.startswith(name):
report = line.strip()
obs = Metar.Metar(line)
print obs.string()
break
if not report:
print "No data for ",name,"\n\n"
except Metar.ParserError, err:
print "METAR code: ",line
print string.join(err.args,", "),"\n"
except:
print "Error retrieving",name,"data","\n"
url = "%s/%s.TXT" % (BASE_URL, name)
if debug:
sys.stderr.write("[ "+url+" ]")
try:
urlh = urllib.urlopen(url)
report = ''
for line in urlh:
if line.startswith(name):
report = line.strip()
obs = Metar.Metar(line)
print obs.string()
break
if not report:
print("No data for %s\n\n" % (name,))
except Metar.ParserError, err:
print("METAR code: "+ line)
print(string.join(err.args,", ") + "\n")
except:
print("Error retrieving %s data\n" % (name,))

Loading