#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Fri Mar 24 04:22:31 2017

@author: franklin
"""

"""
Complete the 'extract_airports()' function so that it returns a list of airport
codes, excluding any combinations like "All".

Refer to the 'options.html' file in the tab above for a stripped down version
of what is actually on the website. The test() assertions are based on the
given file.


TO DO
[ ]Get all airports
[ ]Remove combinations like "All"
[ ]Population data list and return

"""

from bs4 import BeautifulSoup
html_page = "data/options.html"


def extract_airports(page):
    data = []
    with open(page, "r") as html:
        # do something here to find the necessary values
        soup = BeautifulSoup(html, "lxml")
        airports_list = soup.find(id="AirportList")
        items_list = airports_list.findAll("option")
        for item_list in items_list:
            if(item_list.string.find("All") == -1):
                data.append(item_list['value'])
    return data


def test():
    data = extract_airports(html_page)
    assert len(data) == 15
    assert "ATL" in data
    assert "ABR" in data

if __name__ == "__main__":
    test()