Example #1
0
 def setUpClass(self):
     with open(COMMENTS_PAGE) as f:
         self.comments = parsers.parse_comments(f.read())
     with open(NO_COMMENTS) as f:
         self.no_comments = parsers.parse_comments(f.read())
     with open(ASK_COMMENTS) as f:
         self.ask_comments = parsers.parse_comments(f.read())
Example #2
0
 def setUpClass(self):
     with open(COMMENTS_PAGE) as f:
         self.comments = parsers.parse_comments(f.read())
     with open(NO_COMMENTS) as f:
         self.no_comments = parsers.parse_comments(f.read())
     with open(ASK_COMMENTS) as f:
         self.ask_comments = parsers.parse_comments(f.read())
Example #3
0
def update_page(db_key, path):
    """Updates a page in the database

    The page is downloaded, parsed and then stored in the database as a
    JSON string. This string is also returned by the function.

    :db_key: a redis string of the key where the stories page will be stored
    :path: the HN URL path where the page will be downloaded from

    Raises NotFound when the page could not be found on the remote
    server or ServerError in case the server returned a response that we
    could not understand. (It's still the server's fault because it
    doesn't even have sensible status codes)

    """
    res = hn_get(path)
    if db_key.startswith('/pages'):
        result = parse_stories(res.text)
    elif db_key.startswith('/comments'):
        result = parse_comments(res.text)
    else:
        raise TypeError('Wrong DB Key.')

    return json.dumps(result)