from typing import Dict
from typing import List
from typing import Tuple


def parse_flight_data() -> Dict[str, List[Tuple[str, str, int]]]:
    """Parse flight data and returns dictionary of flights by month/year
    Returns:
        Dict[str, List[str, str, int]]: d['mm-yy'] = [(origin_code, dest_code, aircraft_code), ...]
    """
    data_paths = {
        'test': 'data/test_flight_data.csv',
        '11-19': 'data/Nov2019_flight_data.csv',
        '12-19': 'data/Dec2019_flight_data.csv',
        '01-20': 'data/Jan2020_flight_data.csv',
        '02-19': 'data/Feb2019_flight_data.csv',
        '03-19': 'data/Mar2019_flight_data.csv',
        '04-19': 'data/Apr2019_flight_data.csv',
        '05-19': 'data/May2019_flight_data.csv',
        '06-19': 'data/Jun2019_flight_data.csv',
        '07-19': 'data/Jul2019_flight_data.csv',
        '08-19': 'data/Aug2019_flight_data.csv',
    }
    flight_data = dict()
    for month_year, data_path in data_paths.items():
        flight_data[month_year] = list()
        with open(data_path) as f:
            lines_to_skip = 1
            i = 0
            for line in f:
                if i < lines_to_skip:
                    i += 1
                    continue
                split_line = line.rstrip().split(',')
                try:
                    int(split_line[11])
                except:
                    raise Exception('Bad line: {}'.format(line))
                flight_data[month_year].append((split_line[4], split_line[8], int(split_line[11])))
    return flight_data