示例#1
0
def ask_for_one_station( txt, l_map=False, space=False):
    result = False
    if l_map == False:
        l_map = utils.only_existing_stations_in_map() # Update l

    if len(l_map) != 0:
        t  = f'{txt}\n'
        t += vt.list_to_col(l, 'left', 3, 25)
        t += 'To add a station, give a wmo-number or a city name'
        while True:
            answ = ask_for_txt( t, default=False, space=space )

            if utils.is_empthy(answ):
                console.log('Please type in something ...', True)
            elif utils.is_quit(answ):
                result = config.answer_quit[0] # Return first el for quit
                break
            elif stations.name_in_list(answ, l_map) or \
                 stations.wmo_in_list(answ, l_map):
               result = stations.find_by_wmo_or_name(answ, l_map)
               console.log(f'{result.wmo}: {result.place} {result.province} selected', True)
               break
            else:
                ask( f'Station: {answ} unknown !\nPress a key to try again...', True )
    else:
        t = 'No weatherdata found in data map. Download weatherdata first.'
        console.log(t, True)

    return result
示例#2
0
def wmo_in_list(wmo, l=False):
    if wmo:
        if l == False:
            l = utils.only_existing_stations_in_map()
        for s in l:
            if s.wmo == wmo:
                return True
    return False
示例#3
0
def from_wmo_to_province(wmo, l=False):
    if wmo_in_list(wmo):
        if l == False:
            l = utils.only_existing_stations_in_map()
        for s in l:
            if s.wmo == wmo:
                return s.province
    return wmo
示例#4
0
def find_by_wmo(wmo, l=False):
    if wmo:
        n = wmo.lower()
        if l == False:
            l = utils.only_existing_stations_in_map()
        for s in l:
            if s.wmo.lower() == n:
                return s
    return False
示例#5
0
def find_by_name(name, l=False):
    if name:
        n = name.lower()
        if l == False:
            l = utils.only_existing_stations_in_map()
        for s in l:
            if s.place.lower() == n:
                return s
    return False
示例#6
0
def name_in_list(name, l=False):
    if name:
        n = name.lower()
        if l == False:
            l = utils.only_existing_stations_in_map()
        for s in l:
            if s.place.lower() == n:
                return True
    return False
示例#7
0
def ask_for_stations( txt, l_map=False, space=False):
    result = list()
    if l_map == False:
        l_map = utils.only_existing_stations_in_map() # Update l

    cnt_map = len(l_map)
    if cnt_map > 0:
        l = [f'{el.wmo} {el.place}' for el in l_map]
        t  = f'{txt}\n'
        t += vt.list_to_col( l, 'left', 4, 23 )
        t += 'To add one station, give a wmo-number or a city name\n'
        t += 'To add more stations, give a wmo-number or a city name separated by a comma\n'
        t += "Press '*' to add all available weather stations"

        while True:
            ask_txt = t
            cnt_result = len(result)
            if cnt_result > 0:
                ask_txt += "\nPress 'n' to move to the next !"

            answ = ask_for_txt( ask_txt + '\n', default=False, space=space )

            if not answ or utils.is_empthy(answ):
                console.log('Please type in something ...', True)
            elif utils.is_quit(answ):
                result = config.answer_quit[0] # Return first el for quit
                break
            elif answ == '*':
                result =  l_map
                break
            elif answ == 'n' and cnt_result > 0:
                break
            else:
                ll = list() # Make a list with stations
                if answ.find(',') != -1:
                    ll = [clear(e) for e in answ.split(',')] # Clean input
                else:
                    if stations.name_in_list(answ, l_map):
                        ll.append(answ)
                    elif stations.wmo_in_list(answ, l_map):
                        ll.append(answ)
                    else:
                        console.log(f'Station: {answ} is unknown !')

                # Add all added stations
                for s in ll:
                    st = stations.find_by_wmo_or_name(s, l_map)
                    if st != False:
                        all = f'{st.wmo} {st.place} {st.province}'
                        if stations.check_if_station_already_in_list( st, result ) != True:
                            result.append(st)
                            console.log(f'Station: {all} added...')
                        else:
                            console.log(f'Station: {all} already added...')
                    else:
                        console.log(f'Station: {answ} not found...')

            cnt_result = len(result) # New count
            if cnt_result == cnt_map:
                console.log('\nAll available weatherstations added...', True)
                break
            elif cnt_result > 0:
                console.log('\nAll weatherstation(s) who are added are: ', True)

                for s in result:
                    console.log(f'{s.wmo}: {s.place} {s.province}', True)

    else:
        t = 'No weatherdata found in data map. Download weatherdata first.'
        console.log(t, True)
        result = False

    return result