askhist_search.py
def search_with(reddit, targets, optional, n):
    """Search for posts containing all of the keywords in target,
    and at least one of the keywords in optional

    Returns the (title, shortlink) of each answer"""
    askhistorians = reddit.subreddit("askhistorians")

    links = []
    search_string = build_searchstring(targets, optional)
    # r/askhistorians posts always have an automod comment first, so ignore 1-comment posts
    posts = (p for p in askhistorians.search(search_string, limit=n) if p.num_comments > 1)
    for post in posts:
        # A post is answered if it has comments which are not written
        # by the mods. We only need one, so get the first one of these
        answer = next((comment for comment in post.comments
                      if comment.author is not None
                      and comment.author.name not in MODS), None)

        if answer is not None:
            # Check if the comment actually just points to other comments
            nested = check_redirect(reddit, answer)
            if nested:
                links += nested
            else:
                links.append((post.title, post.shortlink))
    return links
Search for posts containing all of the keywords in target,
    and at least one of the keywords in optional

    Returns the (title, shortlink) of each answer
Search for posts containing all of the keywords in target,
and at least one of the keywords in optional

Returns the (title, shortlink) of each answer
Search for posts containing all of the keywords in target and at least one of the keywords in optional Returns the ( title shortlink ) of each answer
def search_with(reddit, targets, optional, n):
    askhistorians = reddit.subreddit("askhistorians")
    links = []
    search_string = build_searchstring(targets, optional)
    posts = (p for p in askhistorians.search(search_string, limit=n) if p.num_comments > 1)
    for post in posts:
        answer = next((comment for comment in post.comments
                      if comment.author is not None
                      and comment.author.name not in MODS), None)
        if answer is not None:
            nested = check_redirect(reddit, answer)
            if nested:
                links += nested
            else:
                links.append((post.title, post.shortlink))
    return links
def search_with ( reddit , targets , optional , n ) : askhistorians = reddit . subreddit ( "askhistorians" ) links = [ ] search_string = build_searchstring ( targets , optional ) posts = ( p for p in askhistorians . search ( search_string , limit = n ) if p . num_comments > 1 ) for post in posts : answer = next ( ( comment for comment in post . comments if comment . author is not None and comment . author . name not in MODS ) , None ) if answer is not None : nested = check_redirect ( reddit , answer ) if nested : links += nested else : links . append ( ( post . title , post . shortlink ) ) return links
Search for posts containing all of the keywords in target,
and at least one of the keywords in optional
Search for posts containing all of the keywords in target and at least one of the keywords in optional
"""Search for posts containing all of the keywords in target,
    and at least one of the keywords in optional

    Returns the (title, shortlink) of each answer""" # r/askhistorians posts always have an automod comment first, so ignore 1-comment posts # A post is answered if it has comments which are not written # by the mods. We only need one, so get the first one of these # Check if the comment actually just points to other comments
reddit
targets
optional
n