| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
"""Python module to provide station information from the ICAO identifiers.""" |
| 5 |
import os |
| 6 |
from metar.Datatypes import position |
| 7 |
|
| 8 |
|
| 9 |
class station: |
| 10 |
"""An object representing a weather station.""" |
| 11 |
|
| 12 |
def __init__( |
| 13 |
self, id, city=None, state=None, country=None, latitude=None, longitude=None |
| 14 |
): |
| 15 |
self.id = id |
| 16 |
self.city = city |
| 17 |
self.state = state |
| 18 |
self.country = country |
| 19 |
self.position = position(latitude, longitude) |
| 20 |
if self.state: |
| 21 |
self.name = "%s, %s" % (self.city, self.state) |
| 22 |
else: |
| 23 |
self.name = self.city |
| 24 |
|
| 25 |
|
| 26 |
current_dir = os.path.dirname(__file__) |
| 27 |
station_file_name = os.path.join(current_dir, "nsd_cccc.txt") |
| 28 |
station_file_url = "http://www.noaa.gov/nsd_cccc.txt" |
| 29 |
|
| 30 |
stations = {} |
| 31 |
|
| 32 |
fh = open(station_file_name, "r") |
| 33 |
for line in fh: |
| 34 |
f = line.strip().split(";") |
| 35 |
stations[f[0]] = station(f[0], f[3], f[4], f[5], f[7], f[8]) |
| 36 |
fh.close() |
| 37 |
|
| 38 |
if __name__ == "__main__": |
| 39 |
for id in ["KEWR", "KIAD", "KIWI", "EKRK"]: |
| 40 |
print(id, stations[id].name, stations[id].country) |