from typing import List
from typing import Dict
import requests
from bs4 import BeautifulSoup


def get_super_hero_ids() -> List[Dict]:
    """Pull Super Hero IDs

    Scrape the Super Hero API website for IDs.

    ..note:
        No endpoint exists to pull super hero IDs
        from API calls.

    Returns:
        List of super hero IDs & names
    
    Raises:
        Exception: Error occuring normally from API connection
    """
    try:
        headers={
            'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
            'accept-language': 'en-US,en;q=0.5',
            'connection': 'keep-alive',
            'DNT': '1',
            'host': 'superheroapi.com',
            'upgrade-insecure-requests': '1',
            'user-agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:65.0) Gecko/20100101 Firefox/65.0'
        }
        source = requests.get('https://superheroapi.com/ids.html', headers=headers)
        source = BeautifulSoup(source.text, 'html.parser')
        tables = source.select('.container-fluid table')
        ids = []
        
        for t in tables:
            rows = t.select('tbody tr')
            
            for r in rows:
                elem = r.find_all('td')
                ids.append({
                    'id': elem[0].text,
                    'name': elem[1].text
                })
        
        return ids
    except Exception:
        raise Exception('Can\'t Connect to Super Hero API ID Table')