import csv


def parse_domains(filename):
    """
    Parse a CSV file with domains
    in the format of:
        Rank, URL, Linking Root Domains, External Links, mozRank, mozTrust

    Download CSV from: https://moz.com/top500/domains/csv
    """
    print('Parsing domains from {0}'.format(filename))
    domains = []
    with open(filename, 'r') as csvfile:
        reader = csv.reader(csvfile)
        for row in reader:
            url = row[1]
            if url == 'URL':  # that's the header
                continue
            domain_name, tld = url.rstrip('/').rsplit('.', maxsplit=1)
            domains.append((domain_name, tld))

    return domains