def format_post_reply(request, subreddit):
    """
    :param request: comment text or post title
    :param subreddit: PRAW subreddit object or name of subreddit (without the /r/)
    :return: a paragraph of info and links about the episode, formatted for Reddit
    :except: omdb_requester.CustomError, post_parser.ParseError, comment_formatter.CustomError
    """
    missingInfo = 0
    released = True

    season, episode = post_parser.parse(request)
    subreddit = str(subreddit).lower()  # clean input
    show = subreddit_to_show[subreddit]
    episode_info = omdb_requester.get_info(show, season, episode)

    if (
        episode_info["Year"].isdigit()
        and int(episode_info["Year"]) > datetime.now().year
        or subreddit in limitedNetflixRelease
        and int(season) + int(episode) / 100 > limitedNetflixRelease[subreddit]
    ):
        released = False

    netflix = ""
    if released:
        try:
            netflix_link = netflix_requester.get_netflix_link(show)
            if netflix_link is None:
                missingInfo += 1
                logging.warning("netflix link is None")
            else:
                netflix = "[Watch on Netflix](" + netflix_link + ") | "
        except netflix_requester.CustomError as e:
            logging.warning(e)
            missingInfo += 1
    else:
        missingInfo += 1

    plot = episode_info["Plot"]
    if plot == "N/A":
        plot = ""
        missingInfo += 1
    else:
        if subreddit in spoilers:
            plot = spoilers[subreddit].format(plot)

    if missingInfo == 2:
        raise NotEnoughInfoError

    if episode_info["imdbRating"] == "N/A":
        rating = ""
    else:
        rating = "[{}] ".format(episode_info["imdbRating"])

    return postReply.format(
        title=episode_info["Title"], id=episode_info["imdbID"], rating=rating, netflix=netflix, plot=plot
    )
def format_post_reply(request, subreddit):
    """
    :param request: comment text or post title
    :param subreddit: PRAW subreddit object or name of subreddit (without the /r/)
    :return: a paragraph of info and links about the episode, formatted for Reddit
    :except: omdb_requester.CustomError, post_parser.ParseError, comment_formatter.CustomError
    """
    missingInfo = 0
    released = True

    season, episode = post_parser.parse(request)
    subreddit = str(subreddit).lower()  # clean input
    show = subreddit_to_show[subreddit]
    episode_info = omdb_requester.get_info(show, season, episode)

    if episode_info['Year'].isdigit() and int(episode_info['Year']) > datetime.now().year\
        or subreddit in limitedNetflixRelease and int(season)+int(episode)/100 > limitedNetflixRelease[subreddit]:
        released = False

    netflix = ''
    if released:
        try:
            netflix_link = netflix_requester.get_netflix_link(show)
            netflix = "[Watch on Netflix](" + netflix_link + ") | "
        except KeyError as e:
            logging.warning(e)
            missingInfo += 1
    else:
        missingInfo += 1

    plot = episode_info['Plot']
    if plot == "N/A" or plot == '':
        plot = ''
        missingInfo += 1
    else:
        if subreddit in spoilers:
            plot = spoilers[subreddit].format(plot)
        plot = "\n\n> " + plot

    if missingInfo == 2:
        raise NotEnoughInfoError

    if (episode_info['imdbRating'] == 'N/A'):
        rating = ''
    else:
        rating = '[{} ★] '.format(episode_info['imdbRating'])

    return postReply.format(
        title=episode_info['Title'],
        id=episode_info['imdbID'],
        rating=rating,
        netflix=netflix,
        plot=plot,
    )
 def test_good_posts(self):
     for goodPost in goodPosts:
         try:
             parse(goodPost)
         except ParseError:
             self.fail(goodPost)
 def test_bad_posts(self):
     for badPost in badPosts:
         with self.assertRaises(ParseError):
             parse(badPost)
 def test_good_posts(self):
     for goodPost in goodPosts:
         try:
             parse(goodPost)
         except ParseError:
             self.fail(goodPost)
 def test_bad_posts(self):
     for badPost in badPosts:
         with self.assertRaises(ParseError, msg=badPost):
             parse(badPost)