import requests
from bs4 import BeautifulSoup


def check_min_delay() -> float:
    """Requests the Rotten Tomatoes robots.txt and checks for crawl-delay

    Parameters
    ----------
    N/A
        
    Returns
    -------
    float
        minimum delay from crawl-delay directive
        0 if no crawl-delay is listed
    """
    
    user_found = False
    min_delay = 0
    
    f = requests.get('https://www.rottentomatoes.com/robots.txt')
    soup = BeautifulSoup(f.content, 'html.parser')
    lines = str(soup).split('\n')
    
    for line in lines:
        if 'User-agent: *' in line:
            user_found = True
        if user_found and ('crawl-delay' in line):
            min_delay = float(line.split(':')[1].strip())
    if user_found:
        print('Warning: crawl-delay not listed for "User-agent: *". \nReturning 0.')
    return min_delay