コード例 #1
0
def extract_post(post_tree, crawled_pids):
    pid = post_tree.find_element_by_xpath(
        ".//div[@class='flow-item']//code[@class='box-id']").text
    if pid in crawled_pids:
        return None
    else:
        crawled_pids.add(pid)
    pcontent = post_tree.find_element_by_xpath(
        ".//div[@class='flow-item']//div[@class='box-content']").text
    ptime = post_tree.find_element_by_xpath(
        ".//div[@class='flow-item']//time").get_attribute('datetime')[:19]
    ptime = datetime.datetime.strptime(ptime, '%Y-%m-%dT%H:%M:%S')

    new_post = Post(pid, pcontent, ptime)

    for reply_tree in post_tree.find_elements_by_xpath(
            ".//div[@class='flow-reply box']"):
        rid = reply_tree.find_element_by_xpath(".//code[@class='box-id']").text

        rtime = reply_tree.find_element_by_xpath(".//time").get_attribute(
            'datetime')[:19]
        rtime = datetime.datetime.strptime(rtime, '%Y-%m-%dT%H:%M:%S')

        rcontent = reply_tree.find_element_by_xpath(
            ".//div[@class='box-content']").text
        left_paren_pos = rcontent.find('[')
        right_paren_pos = rcontent.find(']')
        name = rcontent[left_paren_pos + 1:right_paren_pos]
        rcontent = rcontent[right_paren_pos + 2:]
        new_post.add_reply(rid, name, rcontent, rtime)

    return new_post
コード例 #2
0
ファイル: board.py プロジェクト: a-hitti/Courseboards
    def expand(self,board,post_id, message=None):
        if not self.in_course_list(board):
            return "whatever."
#            pass
        post = Post(board, post_id=post_id)
        if cherrypy.request.method == 'POST':
            if not message:
                print('Message was empty')
                pass #Add to errors or something...
            else:
                post.add_reply(message)
        post.update()
        #display the post and responses for post_id
        post = Post(board, post_id=post_id)
        #Render the page
           
        name_space = {'post':post,'course':board}
        return str(Template(self.expand_template, name_space))