def get_station_year_text(WMO, WBAN, year):
    '''Basic method to download data from the GSOD database, given a 
    station identifier and year. 

    Parameters
    ----------
    WMO : int or None
         World Meteorological Organization (WMO) identifiers, [-]
    WBAN : int or None
        Weather Bureau Army Navy (WBAN) weather station identifier, [-]
    year : int
        Year data should be retrieved from, [year]
        
    Returns
    -------
    data : str
        Downloaded data file
    '''
    if WMO is None:
        WMO = 999999
    if WBAN is None:
        WBAN = 99999
    station = str(int(WMO)) + '-' + str(int(WBAN)) 
    gsod_year_dir = os.path.join(data_dir, 'gsod', str(year))
    path = os.path.join(gsod_year_dir, station + '.op')
    if os.path.exists(path):
        data = open(path).read()
        if data and data != 'Exception':
            return data
        else:
            raise Exception(data)
        
    toget = ('ftp://ftp.ncdc.noaa.gov/pub/data/gsod/' + str(year) + '/' 
             + station + '-' + str(year) +'.op.gz')
    try:
        data = urlopen(toget, timeout=5)
    except Exception as e:
        if not os.path.exists(gsod_year_dir):
            os.makedirs(gsod_year_dir)
        open(path, 'w').write('Exception')
        raise Exception('Could not obtain desired data; check '
                        'if the year has data published for the '
                        'specified station and the station was specified '
                        'in the correct form. The full error is %s' %(e))
        
    data = data.read()
    data_thing = StringIO(data)

    f = gzip.GzipFile(fileobj=data_thing, mode="r")
    year_station_data = f.read()
    try: 
        year_station_data = year_station_data.decode('utf-8')
    except:
        pass
    
    # Cache the data for future use
    if not os.path.exists(gsod_year_dir):
        os.makedirs(gsod_year_dir)
    open(path, 'w').write(year_station_data)
    
    
    return year_station_data
def get_station_year_text ( WMO , WBAN , year ) : if WMO is None : WMO = 999999 if WBAN is None : WBAN = 99999 station = str ( int ( WMO ) ) + '-' + str ( int ( WBAN ) ) gsod_year_dir = os . path . join ( data_dir , 'gsod' , str ( year ) ) path = os . path . join ( gsod_year_dir , station + '.op' ) if os . path . exists ( path ) : data = open ( path ) . read ( ) if data and data != 'Exception' : return data else : raise Exception ( data ) toget = ( 'ftp://ftp.ncdc.noaa.gov/pub/data/gsod/' + str ( year ) + '/' + station + '-' + str ( year ) + '.op.gz' ) try : data = urlopen ( toget , timeout = 5 ) except Exception as e : if not os . path . exists ( gsod_year_dir ) : os . makedirs ( gsod_year_dir ) open ( path , 'w' ) . write ( 'Exception' ) raise Exception ( 'Could not obtain desired data; check ' 'if the year has data published for the ' 'specified station and the station was specified ' 'in the correct form. The full error is %s' % ( e ) ) data = data . read ( ) data_thing = StringIO ( data ) f = gzip . GzipFile ( fileobj = data_thing , mode = "r" ) year_station_data = f . read ( ) try : year_station_data = year_station_data . decode ( 'utf-8' ) except : pass if not os . path . exists ( gsod_year_dir ) : os . makedirs ( gsod_year_dir ) open ( path , 'w' ) . write ( year_station_data ) return year_station_data
Basic method to download data from the GSOD database, given a 
    station identifier and year. 

    Parameters
    ----------
    WMO : int or None
         World Meteorological Organization (WMO) identifiers, [-]
    WBAN : int or None
        Weather Bureau Army Navy (WBAN) weather station identifier, [-]
    year : int
        Year data should be retrieved from, [year]
        
    Returns
    -------
    data : str
        Downloaded data file