Beispiel #1
0
 def threads(self):
     """Property which represents list of board threads."""
     if not self._threads:
         page_json = utils.load_json(self.json_url)
         self._threads = [Thread(self.board_name, thread)
                          for thread in page_json['threads']]
     return self._threads
Beispiel #2
0
def get_all_threads(board):
    """
    Return a list of Thread objects gathered from board.

    The list consists of all threads from board.
    Each element from this list has only original post.
    """
    # TODO: check if board is valid
    url = '{}/{}/catalog.json'.format(DVACH_URL, board)
    data = utils.load_json(url)
    return [Thread(board, thread_data) for thread_data in data.get('threads')]
Beispiel #3
0
def get_preview(board):
    """
    Return a dictionary which represents light version of threads.

    Keys in result dictionary are thread numbers.
    Values are titles of original posts.
    """
    # TODO: check if board is valid
    url = '{}/{}/threads.json'.format(DVACH_URL, board)
    data = utils.load_json(url)
    return {
        thread['num']: thread['subject'] for thread in data.get('threads')
    }
Beispiel #4
0
    def update(self):
        """Update thread's content to the latest data."""

        thread_json = utils.load_json(self.json_url)
        self.title = thread_json['title']
        self.files_count = int(thread_json['files_count'])
        self.posts_count = int(thread_json['posts_count'])

        posts_length = len(self) - 1  # OP is omitted
        gap = self.posts_count - posts_length
        if gap:
            missed_posts = thread_json['threads'][0]['posts'][-gap:]
            self.posts += [Post(self, data) for data in missed_posts]
Beispiel #5
0
    def __init__(self, board_name, data=None, num=None):
        self.board_name = board_name
        self.num = None
        self.original_post = None
        self.posts = None
        self._url = None
        self._json_url = None
        self.title = None
        self.posts_count = None
        self.files_count = None

        if num:
            # initialization by thread number
            self.num = str(num)
            data = utils.load_json(self.json_url)
        elif not data:
            # no data, no num
            raise Exception('Invalid set of initial arguments')
        self._parse_json(data)