import requests
import re
from sys import stderr
from .parse import parseEpisode
from .dataclasses import Episode
from .constants import req_headers

def fetchContent(url):
    '''
    Request a url and return the contents.
    '''
    req = requests.get(url, headers=req_headers)
    req.raise_for_status()
    return req.text


def episodeFactory(eps_url, eps_url_pattern):
    '''
    Fetch the content from an episode page and convert it to an Episode instance.
    '''
    eps = None
    try:
        season, episode = map(int, re.search(eps_url_pattern, eps_url).groups())
        content = fetchContent(eps_url)
        if content:
            quotes = parseEpisode(content)
            eps = Episode(episode, season, quotes)
    except AttributeError:
        print("URL does not match expected format: {}".format(eps_url), file=stderr)
    except requests.RequestException:
        print("Request failed for {}".format(eps_url), file=stderr)
    return eps


590d859561df2170783233c09da9b04c0d73aabc
<mask token>

<mask token>


def fetchContent(url):
    """
    Request a url and return the contents.
    """
    req = requests.get(url, headers=req_headers)
    req.raise_for_status()
    return req.text


<mask token>

<mask token>


def fetchContent(url):
    """
    Request a url and return the contents.
    """
    req = requests.get(url, headers=req_headers)
    req.raise_for_status()
    return req.text


def episodeFactory(eps_url, eps_url_pattern):
    """
    Fetch the content from an episode page and convert it to an Episode instance.
    """
    eps = None
    try:
        season, episode = map(int, re.search(eps_url_pattern, eps_url).groups()
            )
        content = fetchContent(eps_url)
        if content:
            quotes = parseEpisode(content)
            eps = Episode(episode, season, quotes)
    except AttributeError:
        print('URL does not match expected format: {}'.format(eps_url),
            file=stderr)
    except requests.RequestException:
        print('Request failed for {}'.format(eps_url), file=stderr)
    return eps

import requests
import re
from sys import stderr
from .parse import parseEpisode
from .dataclasses import Episode
from .constants import req_headers


def fetchContent(url):
    """
    Request a url and return the contents.
    """
    req = requests.get(url, headers=req_headers)
    req.raise_for_status()
    return req.text


def episodeFactory(eps_url, eps_url_pattern):
    """
    Fetch the content from an episode page and convert it to an Episode instance.
    """
    eps = None
    try:
        season, episode = map(int, re.search(eps_url_pattern, eps_url).groups()
            )
        content = fetchContent(eps_url)
        if content:
            quotes = parseEpisode(content)
            eps = Episode(episode, season, quotes)
    except AttributeError:
        print('URL does not match expected format: {}'.format(eps_url),
            file=stderr)
    except requests.RequestException:
        print('Request failed for {}'.format(eps_url), file=stderr)
    return eps

import requests
import re
from sys import stderr
from .parse import parseEpisode
from .dataclasses import Episode
from .constants import req_headers

def fetchContent(url):
    '''
    Request a url and return the contents.
    '''
    req = requests.get(url, headers=req_headers)
    req.raise_for_status()
    return req.text


def episodeFactory(eps_url, eps_url_pattern):
    '''
    Fetch the content from an episode page and convert it to an Episode instance.
    '''
    eps = None
    try:
        season, episode = map(int, re.search(eps_url_pattern, eps_url).groups())
        content = fetchContent(eps_url)
        if content:
            quotes = parseEpisode(content)
            eps = Episode(episode, season, quotes)
    except AttributeError:
        print("URL does not match expected format: {}".format(eps_url), file=stderr)
    except requests.RequestException:
        print("Request failed for {}".format(eps_url), file=stderr)
    return eps

