Skip to content

Commit

Permalink
Added find_station method to StationList class
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiolsilva committed Oct 2, 2023
1 parent b8f8a40 commit 7192f92
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions bbp/comps/station_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,24 @@ def get_station_list(self):
"""
return self.site_list

def find_station(self, station_name):
"""
Returns station object for station matching station_name,
otherwise returns None
"""
matching_list = [station for station in self.site_list if station.scode == station_name]

# Not found
if not len(matching_list):
return None

# Alert user that are multiple matches
if len(matching_list) > 1:
print("[WARNING]: multiple stations match station name %s!" % (station_name))

# Return match
return matching_list[0]

if __name__ == "__main__":
print("Testing Module: %s" % (sys.argv[0]))
STATION_LIST = StationList(sys.argv[1])
Expand Down

0 comments on commit 7192f92

Please sign in to comment.